From e7fb52b3a5ddffe1bba848e4966159868b6951f0 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 12 May 2018 20:58:58 +0200 Subject: [PATCH] stdioext: Fix compilation errors with newer Android headers. * lib/stdio-impl.h (fp_, fp_ub): Define differently for Android. (__SLBF, __SNBF, __SRD, __SWR, __SRW, __SEOF, __SERR, __SOFF): Define fallbacks for Android. * lib/fpending.c: Update comments. * lib/fpurge.c: Likewise. * lib/freadable.h: Likewise. * lib/freadable.c: Likewise. * lib/freadahead.c: Likewise. * lib/freading.h: Likewise. * lib/freadptr.c: Likewise. * lib/fseterr.c: Likewise. * lib/fwritable.h: Likewise. * lib/fwritable.c: Likewise. * lib/fwriting.h: Likewise. * lib/fwriting.c: Likewise. --- ChangeLog | 19 +++++++++++++++ lib/fpending.c | 3 +++ lib/fpurge.c | 4 ++-- lib/freadable.c | 3 +++ lib/freadable.h | 2 +- lib/freadahead.c | 3 +++ lib/freading.h | 2 +- lib/freadptr.c | 3 +++ lib/fseterr.c | 3 +++ lib/fwritable.c | 3 +++ lib/fwritable.h | 2 +- lib/fwriting.c | 3 +++ lib/fwriting.h | 2 +- lib/stdio-impl.h | 60 +++++++++++++++++++++++++++++++++++++++++++++--- 14 files changed, 103 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0bd75bbc24..f4c0138511 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2018-05-13 Bruno Haible + + stdioext: Fix compilation errors with newer Android headers. + * lib/stdio-impl.h (fp_, fp_ub): Define differently for Android. + (__SLBF, __SNBF, __SRD, __SWR, __SRW, __SEOF, __SERR, __SOFF): Define + fallbacks for Android. + * lib/fpending.c: Update comments. + * lib/fpurge.c: Likewise. + * lib/freadable.h: Likewise. + * lib/freadable.c: Likewise. + * lib/freadahead.c: Likewise. + * lib/freading.h: Likewise. + * lib/freadptr.c: Likewise. + * lib/fseterr.c: Likewise. + * lib/fwritable.h: Likewise. + * lib/fwritable.c: Likewise. + * lib/fwriting.h: Likewise. + * lib/fwriting.c: Likewise. + 2018-05-13 Bruno Haible doc: Add info about Android versions 2.0 to 8.1. diff --git a/lib/fpending.c b/lib/fpending.c index 7bc235deda..de370d4b10 100644 --- a/lib/fpending.c +++ b/lib/fpending.c @@ -24,6 +24,9 @@ #include "stdio-impl.h" +/* This file is not used on systems that already have the __fpending function, + namely glibc >= 2.2, Solaris >= 7, Android API >= 23. */ + /* Return the number of pending (aka buffered, unflushed) bytes on the stream, FP, that is open for writing. */ size_t diff --git a/lib/fpurge.c b/lib/fpurge.c index 554790b562..f9c82cdadd 100644 --- a/lib/fpurge.c +++ b/lib/fpurge.c @@ -19,7 +19,7 @@ /* Specification. */ #include -#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7 */ +#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7, Android API >= 23 */ # include #endif #include @@ -29,7 +29,7 @@ int fpurge (FILE *fp) { -#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7, musl libc */ +#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7, Android API >= 23, musl libc */ __fpurge (fp); /* The __fpurge function does not have a return value. */ diff --git a/lib/freadable.c b/lib/freadable.c index 53cdbee08a..f4ce079202 100644 --- a/lib/freadable.c +++ b/lib/freadable.c @@ -25,6 +25,9 @@ # include #endif +/* This file is not used on systems that have the __freadable function, + namely glibc >= 2.2, Solaris >= 7, Android API >= 23, musl libc. */ + bool freadable (FILE *fp) { diff --git a/lib/freadable.h b/lib/freadable.h index 000e95babd..4b51570d5e 100644 --- a/lib/freadable.h +++ b/lib/freadable.h @@ -22,7 +22,7 @@ STREAM must not be wide-character oriented. The result doesn't change until the stream is closed or re-opened. */ -#if HAVE___FREADABLE /* glibc >= 2.2, Solaris >= 7, musl libc */ +#if HAVE___FREADABLE /* glibc >= 2.2, Solaris >= 7, Android API >= 23, musl libc */ # include # define freadable(stream) (__freadable (stream) != 0) diff --git a/lib/freadahead.c b/lib/freadahead.c index ed3dd0ebda..fd5411c57e 100644 --- a/lib/freadahead.c +++ b/lib/freadahead.c @@ -27,6 +27,9 @@ extern size_t __sreadahead (FILE *); #endif +/* This file is not used on systems that have the __freadahead function, + namely musl libc. */ + size_t freadahead (FILE *fp) { diff --git a/lib/freading.h b/lib/freading.h index 29d92b1391..31d71fdb75 100644 --- a/lib/freading.h +++ b/lib/freading.h @@ -33,7 +33,7 @@ STREAM must not be wide-character oriented. */ #if HAVE___FREADING && (!defined __GLIBC__ || defined __UCLIBC__ || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 7)) -/* Solaris >= 7, not glibc >= 2.2, but glibc >= 2.7, or musl libc */ +/* Solaris >= 7, Android API >= 29, not glibc >= 2.2, but glibc >= 2.7, or musl libc */ # include # define freading(stream) (__freading (stream) != 0) diff --git a/lib/freadptr.c b/lib/freadptr.c index 3afa621492..91765595fd 100644 --- a/lib/freadptr.c +++ b/lib/freadptr.c @@ -23,6 +23,9 @@ #include "stdio-impl.h" +/* This file is not used on systems that have the __freadptr function, + namely musl libc. */ + const char * freadptr (FILE *fp, size_t *sizep) { diff --git a/lib/fseterr.c b/lib/fseterr.c index fd9da63381..81f51edade 100644 --- a/lib/fseterr.c +++ b/lib/fseterr.c @@ -23,6 +23,9 @@ #include "stdio-impl.h" +/* This file is not used on systems that have the __fseterr function, + namely musl libc. */ + void fseterr (FILE *fp) { diff --git a/lib/fwritable.c b/lib/fwritable.c index 24a148aee2..79e7c38ac7 100644 --- a/lib/fwritable.c +++ b/lib/fwritable.c @@ -25,6 +25,9 @@ # include #endif +/* This file is not used on systems that have the __fwritable function, + namely glibc >= 2.2, Solaris >= 7, Android API >= 23, musl libc. */ + bool fwritable (FILE *fp) { diff --git a/lib/fwritable.h b/lib/fwritable.h index 1821352d0c..43ce3d6772 100644 --- a/lib/fwritable.h +++ b/lib/fwritable.h @@ -22,7 +22,7 @@ STREAM must not be wide-character oriented. The result doesn't change until the stream is closed or re-opened. */ -#if HAVE___FWRITABLE /* glibc >= 2.2, Solaris >= 7, musl libc */ +#if HAVE___FWRITABLE /* glibc >= 2.2, Solaris >= 7, Android API >= 23, musl libc */ # include # define fwritable(stream) (__fwritable (stream) != 0) diff --git a/lib/fwriting.c b/lib/fwriting.c index 9be6fb2200..4ffa12d321 100644 --- a/lib/fwriting.c +++ b/lib/fwriting.c @@ -21,6 +21,9 @@ #include "stdio-impl.h" +/* This file is not used on systems that have the __fwritable function, + namely glibc >= 2.2, Solaris >= 7, Android API >= 29, musl libc. */ + bool fwriting (FILE *fp) { diff --git a/lib/fwriting.h b/lib/fwriting.h index f2a6c5ecb5..42f7e9435a 100644 --- a/lib/fwriting.h +++ b/lib/fwriting.h @@ -33,7 +33,7 @@ STREAM must not be wide-character oriented. */ -#if HAVE___FWRITING /* glibc >= 2.2, Solaris >= 7, musl libc */ +#if HAVE___FWRITING /* glibc >= 2.2, Solaris >= 7, Android API >= 29, musl libc */ # include # define fwriting(stream) (__fwriting (stream) != 0) diff --git a/lib/stdio-impl.h b/lib/stdio-impl.h index 7a0ac4d50b..393ef0cf58 100644 --- a/lib/stdio-impl.h +++ b/lib/stdio-impl.h @@ -60,25 +60,79 @@ # define _flags pub._flags # define _r pub._r # define _w pub._w +# elif defined __ANDROID__ /* Android */ + /* Up to this commit from 2015-10-12 + + the innards of FILE were public, and fp_ub could be defined like for OpenBSD, + see + and . + After this commit, the innards of FILE are hidden. */ +# define fp_ ((struct { unsigned char *_p; \ + int _r; \ + int _w; \ + int _flags; \ + int _file; \ + struct { unsigned char *_base; size_t _size; } _bf; \ + int _lbfsize; \ + void *_cookie; \ + void *_close; \ + void *_read; \ + void *_seek; \ + void *_write; \ + struct { unsigned char *_base; size_t _size; } _ext; \ + unsigned char *_up; \ + int _ur; \ + unsigned char _ubuf[3]; \ + unsigned char _nbuf[1]; \ + struct { unsigned char *_base; size_t _size; } _lb; \ + int _blksize; \ + fpos_t _offset; \ + /* More fields, not relevant here. */ \ + } *) fp) # else # define fp_ fp # endif -# if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ || defined __minix || defined __ANDROID__ /* NetBSD >= 1.5ZA, OpenBSD, Minix 3, Android */ +# if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ || defined __minix /* NetBSD >= 1.5ZA, OpenBSD, Minix 3 */ /* See - and */ + and + and */ struct __sfileext { struct __sbuf _ub; /* ungetc buffer */ /* More fields, not relevant here. */ }; # define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub -# else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, Mac OS X, Cygwin, Android */ +# elif defined __ANDROID__ /* Android */ + struct __sfileext + { + struct { unsigned char *_base; size_t _size; } _ub; /* ungetc buffer */ + /* More fields, not relevant here. */ + }; +# define fp_ub ((struct __sfileext *) fp_->_ext._base)->_ub +# else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, Mac OS X, Cygwin */ # define fp_ub fp_->_ub # endif # define HASUB(fp) (fp_ub._base != NULL) +# if defined __ANDROID__ /* Android */ + /* Needed after this commit from 2016-01-25 + */ +# ifndef __SEOF +# define __SLBF 1 +# define __SNBF 2 +# define __SRD 4 +# define __SWR 8 +# define __SRW 0x10 +# define __SEOF 0x20 +# define __SERR 0x40 +# endif +# ifndef __SOFF +# define __SOFF 0x1000 +# endif +# endif + #endif -- 2.39.5