X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Ffreadseek.c;h=99af4370a1cd76b34f936525ff1e9624b6ea4462;hb=ea6b0b0c5caf18a059bb974a2d0c1739d5be671c;hp=4299e82fea46dce1e03da6adce17133bff3daa84;hpb=a2b445a2c93224ca2999ad3a7aa6b4b2a752e7a0;p=gnulib.git diff --git a/lib/freadseek.c b/lib/freadseek.c index 4299e82fe..99af4370a 100644 --- a/lib/freadseek.c +++ b/lib/freadseek.c @@ -1,5 +1,5 @@ /* Skipping input from a FILE stream. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -34,7 +34,7 @@ static inline void freadptrinc (FILE *fp, size_t increment) { /* Keep this code in sync with freadptr! */ -#if defined _IO_ferror_unlocked || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Linux libc5 */ +#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ fp->_IO_read_ptr += increment; #elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */ fp_->_p += increment; @@ -53,6 +53,8 @@ freadptrinc (FILE *fp, size_t increment) # endif #elif defined __QNX__ /* QNX */ fp->_Next += increment; +#elif defined __MINT__ /* Atari FreeMiNT */ + fp->__bufp += increment; #elif defined SLOW_BUT_NO_HACKS /* users can define this */ #else #error "Please port gnulib freadseek.c to your platform! Look at the definition of getc, getc_unlocked on your system, then report this to bug-gnulib." @@ -78,24 +80,24 @@ freadseek (FILE *fp, size_t offset) size_t buffered; if (freadptr (fp, &buffered) != NULL && buffered > 0) - { - size_t increment = (buffered < offset ? buffered : offset); - - freadptrinc (fp, increment); - offset -= increment; - if (offset == 0) - return 0; - total_buffered -= increment; - if (total_buffered == 0) - break; - } + { + size_t increment = (buffered < offset ? buffered : offset); + + freadptrinc (fp, increment); + offset -= increment; + if (offset == 0) + return 0; + total_buffered -= increment; + if (total_buffered == 0) + break; + } /* Read one byte. If we were reading from the ungetc buffer, this - switches the stream back to the main buffer. */ + switches the stream back to the main buffer. */ if (fgetc (fp) == EOF) - goto eof; + goto eof; offset--; if (offset == 0) - return 0; + return 0; total_buffered--; } @@ -104,21 +106,21 @@ freadseek (FILE *fp, size_t offset) if (fd >= 0 && lseek (fd, 0, SEEK_CUR) >= 0) { /* FP refers to a regular file. fseek is most efficient in this case. */ - return fseek (fp, offset, SEEK_CUR); + return fseeko (fp, offset, SEEK_CUR); } else { /* FP is a non-seekable stream, possibly not even referring to a file - descriptor. Read OFFSET bytes explicitly and discard them. */ + descriptor. Read OFFSET bytes explicitly and discard them. */ char buf[4096]; do - { - size_t count = (sizeof (buf) < offset ? sizeof (buf) : offset); - if (fread (buf, 1, count, fp) < count) - goto eof; - offset -= count; - } + { + size_t count = (sizeof (buf) < offset ? sizeof (buf) : offset); + if (fread (buf, 1, count, fp) < count) + goto eof; + offset -= count; + } while (offset > 0); return 0;