Skip to content

Commit

Permalink
a few additional fread*.c fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cooljeanius committed Jun 28, 2024
1 parent a307293 commit 36b3153
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions freadahead.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@
size_t
freadahead(FILE *fp)
{
#if defined _IO_ftrylockfile || (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ == 1)) /* GNU libc, BeOS, Haiku, Linux libc5 */
#if defined(_IO_EOF_SEEN) || defined(_IO_ftrylockfile) || (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ == 1))
/* GNU libc, BeOS, Haiku, Linux libc5 */
if (fp->_IO_write_ptr > fp->_IO_write_base)
return 0;
return ((fp->_IO_read_end - fp->_IO_read_ptr)
+ ((fp->_flags & _IO_IN_BACKUP)
? (fp->_IO_save_end - fp->_IO_save_base)
: 0));
#elif defined(__sferror) || defined(__DragonFly__) /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
#elif defined(__sferror) || defined(__DragonFly__) || defined(__ANDROID__)
/* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
if (((fp_->_flags & __SWR) != 0) || (fp_->_r < 0))
return 0;
# if defined __DragonFly__
Expand Down
6 changes: 4 additions & 2 deletions freadptr.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ const char *freadptr(FILE *fp, size_t *sizep)
size_t size;

/* Keep this code in sync with freadahead! */
#if defined(_IO_ftrylockfile) || (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ == 1)) /* GNU libc, BeOS, Haiku, Linux libc5 */
#if defined(_IO_EOF_SEEN) || defined(_IO_ftrylockfile) || (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ == 1))
/* GNU libc, BeOS, Haiku, Linux libc5 */
if (fp->_IO_write_ptr > fp->_IO_write_base)
return NULL;
size = (fp->_IO_read_end - fp->_IO_read_ptr);
if (size == 0)
return NULL;
*sizep = size;
return (const char *)fp->_IO_read_ptr;
#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
#elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
/* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
if (((fp_->_flags & __SWR) != 0) || (fp_->_r < 0)) {
return NULL;
}
Expand Down
6 changes: 4 additions & 2 deletions freadseek.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ static inline void freadptrinc(FILE *fp, size_t increment)
/* Keep this code in sync with freadptr! */
#if defined(HAVE___FREADPTRINC) && HAVE___FREADPTRINC /* musl libc */
__freadptrinc(fp, increment);
#elif defined(_IO_ftrylockfile) || (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ == 1)) /* GNU libc, BeOS, Haiku, Linux libc5 */
#elif defined(_IO_EOF_SEEN) || defined(_IO_ftrylockfile) || (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ == 1))
/* GNU libc, BeOS, Haiku, Linux libc5 */
fp->_IO_read_ptr += increment;
#elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
#elif defined __sferror || defined __DragonFly__ || defined __ANDROID__
/* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin, Minix 3, Android */
fp_->_p += increment;
fp_->_r -= (int)increment;
#elif defined __EMX__ /* emx+gcc */
Expand Down

0 comments on commit 36b3153

Please sign in to comment.