diff options
author | Gwenolé Beauchesne <gbeauchesne@mandriva.org> | 2003-06-04 18:31:57 +0000 |
---|---|---|
committer | Gwenolé Beauchesne <gbeauchesne@mandriva.org> | 2003-06-04 18:31:57 +0000 |
commit | 09e967c2d732783b2579e4e120cd9b608404cb00 (patch) | |
tree | 8d2783a6a7e33608c6012efd6a88b8f5694df81d /mdk-stage1/dietlibc/libstdio/fread.c | |
parent | 18fcff49d3c836697d3b75a3d01d31c700e69974 (diff) | |
download | drakx-backup-do-not-use-09e967c2d732783b2579e4e120cd9b608404cb00.tar drakx-backup-do-not-use-09e967c2d732783b2579e4e120cd9b608404cb00.tar.gz drakx-backup-do-not-use-09e967c2d732783b2579e4e120cd9b608404cb00.tar.bz2 drakx-backup-do-not-use-09e967c2d732783b2579e4e120cd9b608404cb00.tar.xz drakx-backup-do-not-use-09e967c2d732783b2579e4e120cd9b608404cb00.zip |
Merge from R9_0-AMD64, most notably:
- AMD64 support to insmod-busybox, minilibc, et al.
- Sync with insmod-modutils 2.4.19 something but everyone should use
dietlibc nowadays
- Factor out compilation and prefix with $(DIET) for dietlibc builds
- 64-bit & varargs fixes
Diffstat (limited to 'mdk-stage1/dietlibc/libstdio/fread.c')
-rw-r--r-- | mdk-stage1/dietlibc/libstdio/fread.c | 55 |
1 files changed, 25 insertions, 30 deletions
diff --git a/mdk-stage1/dietlibc/libstdio/fread.c b/mdk-stage1/dietlibc/libstdio/fread.c index 29afa1489..813a98fb2 100644 --- a/mdk-stage1/dietlibc/libstdio/fread.c +++ b/mdk-stage1/dietlibc/libstdio/fread.c @@ -4,48 +4,43 @@ 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 + i=0; + + if (!j || j/nmemb!=size) return 0; if (stream->ungotten) { + stream->ungotten=0; *(char*)ptr=stream->ungetbuf; - ptr=((char*)ptr)+1; - --j; + ++i; } if (!j) return 1; + +#ifdef WANT_FREAD_OPTIMIZATION + if ( !(stream->flags&FDPIPE) && (j>stream->buflen)) { + size_t tmp=j-i; + int res; + fflush(stream); + while ((res=read(stream->fd,ptr+i,tmp))<(int)tmp) { + if (res==-1) { + stream->flags|=ERRORINDICATOR; + goto exit; + } else if (!res) { + stream->flags|=EOFINDICATOR; + goto exit; + } + i+=res; tmp-=res; + } + return nmemb; + } #endif - for (i=0; i<j; ++i) { + for (; i<j; ++i) { res=fgetc(stream); if (res==EOF) +exit: 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 } |