Subversion Repositories Kolibri OS

Rev

Rev 300 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 300 Rev 324
Line 1... Line -...
1
#include "kolibc.h"
-
 
-
 
1
#include "kolibri.h"
2
#include "kolibri.h"
2
#include 
-
 
3
 
-
 
4
#include "kolibc.h"
-
 
5
 
Line 3... Line 6...
3
 
6
int fill_buff(FILE* f);
Line 4... Line 7...
4
int fill_buff(FILE* f);
7
 
5
 
8
int fread(void* dst,size_t size,size_t count,FILE* f)
6
int fread(void* dst,size_t size,size_t count,FILE* f)
9
{ size_t req;
7
{ size_t req;
10
  size_t cnt;
8
  size_t cnt;
11
  char *p;
9
  char *p = dst;
12
//  if(!((f->mode & FILE_OPEN_READ)|(f->mode & FILE_OPEN_PLUS)))
10
  if(!((f->mode & FILE_OPEN_READ)|(f->mode & FILE_OPEN_PLUS)))
13
//                return 0;
-
 
14
  req=count*size;
-
 
15
  p= (char*)dst;
11
		return 0;
16
  
12
  req=count*size;
17
  if (req+f->filepos+f->strpos > f->filesize)
13
  if (req+f->filepos+f->strpos > f->filesize)
18
                req=f->filesize-f->filepos-f->strpos;
14
		req=f->filesize-f->filepos-f->strpos;
19
  count=0;              
15
  count=0;		
20
  while(req)
16
  while(req)
21
  {
17
  {
22
    if (f->remain)
18
    if (f->remain)
23
    { cnt= (req > f->remain) ? f->remain : req;
19
    { cnt= req > f->remain ? f->remain : req;
24
      memcpy(p,f->stream,cnt);
20
	  memcpy(p,f->stream,cnt);
25
      p+=cnt;
21
	  p+=cnt;
26
      f->stream+=cnt;
22
	  f->stream+=cnt;
27
      f->strpos+=cnt;
23
	  f->strpos+=cnt;
28
      f->remain-=cnt;
24
	  f->remain-=cnt;
29
      count+=cnt;
25
	  count+=cnt;
30
      req-=cnt;
26
	  req-=cnt;
31
    }
27
	}
32
    else
28
	else
33
    {
29
	{
34
      f->filepos+=8192;
-
 
35
      if(!fill_buff(f))
30
	  f->filepos+=4096;
36
      { printf("error reading file %d=",f->filepos); //eof or error
31
	  if(!fill_buff(f))  //eof or error
37
        break;
32
	    break;
38
      }
-
 
39
    };    
33
	}  
40
  };
34
  };
41
  return count/size;
Line 35... Line 42...
35
  return count/size;
42
}
36
}
43
 
37
 
44
int fill_buff(FILE* f)
Line 38... Line 45...
38
int fill_buff(FILE* f)
45
{ int err;
39
{ int err;
46
  size_t bytes;
-
 
47
  
40
  size_t bytes;
48
  err=read_file(f->filename,f->buffer,f->filepos,
41
  
49
                             8192,&bytes);
42
  err=read_file(f->filename,f->buffer,f->filepos,
50
  if(bytes == -1)
43
                             4096,&bytes);
51
    return 0;                           
44
  if (err) return 0; 
52
//  if(!bytes) return 0;
45
  if(!bytes) return 0;
53
  f->stream = f->buffer;
46
  f->stream = f->buffer;
54
  f->remain = 8192;
47
  f->remain = 4096;
55
  f->strpos=0;
-
 
56
  return bytes;