Subversion Repositories Kolibri OS

Rev

Rev 614 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 614 Rev 727
Line 39... Line 39...
39
#include "fileacc.h"
39
#include "fileacc.h"
40
#include "rtcheck.h"
40
#include "rtcheck.h"
41
#include "rtdata.h"
41
#include "rtdata.h"
42
#include "seterrno.h"
42
#include "seterrno.h"
43
#include "lseek.h"
43
#include "lseek.h"
-
 
44
#include "kolibri.h"
Line 44... Line 45...
44
 
45
 
45
typedef struct 
46
typedef struct 
46
{
47
{
47
  char     *name;
48
  char     *name;
48
  unsigned int offset;
49
  unsigned int offset;
Line 49... Line -...
49
}__file_handle;
-
 
50
 
-
 
51
 
-
 
52
int _stdcall read_file (const char *name,char *buff,unsigned offset, unsigned count,unsigned *reads);
50
}__file_handle;
53
 
51
 
54
_WCRTLINK int read( int handle, void *buf, unsigned len )
52
_WCRTLINK int read( int handle, void *buf, unsigned len )
55
{
53
{
56
    unsigned read_len, total_len;
54
    unsigned read_len, total_len;
57
    unsigned reduce_idx, finish_idx;
55
    unsigned reduce_idx, finish_idx;
58
    unsigned iomode_flags;
56
    unsigned iomode_flags;
59
    char *buffer = buf;
57
    char *buffer = buf;
60
    BOOL    rc;
58
    BOOL    rc;
-
 
59
    HANDLE  h;
-
 
60
    unsigned amount_read;
61
    HANDLE  h;
61
    int err;
Line -... Line 62...
-
 
62
    
62
    unsigned amount_read;
63
    __file_handle *fh;
63
    __file_handle *fh;
64
 
64
 
65
    
65
    __handle_check( handle, -1 );
66
    __handle_check( handle, -1 );
66
    __ChkTTYIOMode( handle );
67
    __ChkTTYIOMode( handle );
Line 80... Line 81...
80
    fh = (__file_handle*) __getOSHandle( handle );
81
    fh = (__file_handle*) __getOSHandle( handle );
Line 81... Line 82...
81
 
82
 
82
    if( iomode_flags & _BINARY )   /* if binary mode */
83
    if( iomode_flags & _BINARY )   /* if binary mode */
Line 83... Line 84...
83
    {
84
    {
84
 
-
 
85
      if(read_file(fh->name,buffer,fh->offset,len,&amount_read))
-
 
86
      {
-
 
87
        if ( amount_read == 0)
-
 
88
          return (-1);   
85
 
89
      }
86
      err=read_file(fh->name,buffer,fh->offset,len,&amount_read);
-
 
87
      fh->offset+=amount_read;
-
 
88
      total_len = amount_read;
-
 
89
      
-
 
90
      if(err)
-
 
91
        if ( amount_read == 0)
90
      fh->offset+=amount_read;
92
          return (-1);   
91
      total_len = amount_read;
93
      
92
    }
94
    }
93
    else
95
    else
94
    {
96
    {
95
        total_len = 0;
97
        total_len = 0;
96
        read_len = len;
98
        read_len = len;
97
        do
99
        do
98
        {
100
        {
-
 
101
          err=read_file(fh->name,buffer,fh->offset,len,&amount_read);
99
          if(read_file(fh->name,buffer,fh->offset,len,&amount_read))
102
          fh->offset+=amount_read;
100
          {
103
            
101
            if( amount_read == 0 )
-
 
102
            {                    /* EOF */
-
 
103
                break;
104
          if( amount_read == 0 )
104
            }
105
            break;                   /* EOF */
105
          }  
106
            
106
          reduce_idx = 0;
107
          reduce_idx = 0;
107
          finish_idx = reduce_idx;
108
          finish_idx = reduce_idx;
108
          for( ; reduce_idx < amount_read; ++reduce_idx )
109
          for( ; reduce_idx < amount_read; ++reduce_idx )