Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/feature_unix/sys/src/libstdio/fread.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/*
2
 * pANS stdio -- fread
3
 */
4
#include "iolib.h"
5
 
6
#define BIGN (BUFSIZ/2)
7
 
8
long fread(void *p, long recl, long nrec, FILE *f){
9
	char *s;
10
	int n, d, c;
11
 
12
	s=(char *)p;
13
	n=recl*nrec;
14
	while(n>0){
15
		d=f->wp-f->rp;
16
		if(d>0){
17
			if(d>n)
18
				d=n;
19
			memmove(s, f->rp, d);
20
			f->rp+=d;
21
		}else{
22
			if(n >= BIGN && f->state==RD && !(f->flags&STRING) && f->buf!=f->unbuf){
23
				d=read(f->fd, s, n);
24
				if(d<=0){
25
					f->state=(d==0)?END:ERR;
26
					goto ret;
27
				}
28
			}else{
29
 				c=_IO_getc(f);
30
				if(c==EOF)
31
					goto ret;
32
				*s=c;
33
				d=1;
34
			}
35
		}
36
		s+=d;
37
		n-=d;
38
	}
39
    ret:
40
	return (s-(char *)p)/(recl?recl:1);
41
}