diff options
author | Guillaume Cottenceau <gc@mandriva.com> | 2001-05-14 13:47:49 +0000 |
---|---|---|
committer | Guillaume Cottenceau <gc@mandriva.com> | 2001-05-14 13:47:49 +0000 |
commit | f15aa3a552022743398a652165d76bf912c715e5 (patch) | |
tree | b58f8b4c47fc571fbb498d83a4bd4fca226ac6c4 /mdk-stage1/dietlibc/libstdio/fread.c | |
parent | 189b01c358a1181ddc951adba97a0258d5fc2cf1 (diff) | |
download | drakx-f15aa3a552022743398a652165d76bf912c715e5.tar drakx-f15aa3a552022743398a652165d76bf912c715e5.tar.gz drakx-f15aa3a552022743398a652165d76bf912c715e5.tar.bz2 drakx-f15aa3a552022743398a652165d76bf912c715e5.tar.xz drakx-f15aa3a552022743398a652165d76bf912c715e5.zip |
Initial revision
Diffstat (limited to 'mdk-stage1/dietlibc/libstdio/fread.c')
-rw-r--r-- | mdk-stage1/dietlibc/libstdio/fread.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/mdk-stage1/dietlibc/libstdio/fread.c b/mdk-stage1/dietlibc/libstdio/fread.c new file mode 100644 index 000000000..29afa1489 --- /dev/null +++ b/mdk-stage1/dietlibc/libstdio/fread.c @@ -0,0 +1,51 @@ +#include <sys/types.h> +#include "dietstdio.h" +#include <unistd.h> + +size_t fread( void *ptr, size_t size, size_t nmemb, FILE *stream) { + int res; +#ifdef WANT_BUFFERED_STDIO + unsigned long i,j; + j=size*nmemb; +#ifdef WANT_UNGETC + if (stream->ungotten) { + *(char*)ptr=stream->ungetbuf; + ptr=((char*)ptr)+1; + --j; + } + if (!j) return 1; +#endif + for (i=0; i<j; ++i) { + res=fgetc(stream); + if (res==EOF) + return i/size; + else + ((unsigned char*)ptr)[i]=(unsigned char)res; + } + return nmemb; +#else +#ifdef WANT_UNGETC + unsigned long j=size*nmemb; +#endif + fflush(stream); +#ifdef WANT_UNGETC + if (stream->ungotten) { + *(char*)ptr=stream->ungetbuf; + ptr=((char*)ptr)+1; + --j; + } + if (!j) return 1; + res=read(stream->fd,ptr,j); +#else + res=read(stream->fd,ptr,size*nmemb); +#endif + if (res<0) { + stream->flags|=ERRORINDICATOR; + return 0; + } else if (res<size*nmemb) + if (!(stream->flags & UNSEEKABLE) + || ((stream->flags & UNSEEKABLE) && res == 0)) + stream->flags|=EOFINDICATOR; + return res/size; +#endif +} |