Compiling for Android 4.3 (with recent Android 9.0 header files), I'm seeing compilation failures in the stdioext modules. Such as:
In file included from fseterr.c:24:0: stdio-impl.h:72:22: error: field '_ub' has incomplete type struct __sbuf _ub; /* ungetc buffer */ ^ fseterr.c: In function 'fseterr': fseterr.c:37:6: error: 'FILE' has no member named '_flags' fp_->_flags |= __SERR; ^ fseterr.c:37:18: error: '__SERR' undeclared (first use in this function) fp_->_flags |= __SERR; ^ This fixes them. 2018-05-13 Bruno Haible <br...@clisp.org> 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. diff --git a/lib/fpending.c b/lib/fpending.c index 7bc235d..de370d4 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 554790b..f9c82cd 100644 --- a/lib/fpurge.c +++ b/lib/fpurge.c @@ -19,7 +19,7 @@ /* Specification. */ #include <stdio.h> -#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7 */ +#if HAVE___FPURGE /* glibc >= 2.2, Haiku, Solaris >= 7, Android API >= 23 */ # include <stdio_ext.h> #endif #include <stdlib.h> @@ -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 53cdbee..f4ce079 100644 --- a/lib/freadable.c +++ b/lib/freadable.c @@ -25,6 +25,9 @@ # include <fcntl.h> #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 000e95b..4b51570 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 <stdio_ext.h> # define freadable(stream) (__freadable (stream) != 0) diff --git a/lib/freadahead.c b/lib/freadahead.c index ed3dd0e..fd5411c 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 29d92b1..31d71fd 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 <stdio_ext.h> # define freading(stream) (__freading (stream) != 0) diff --git a/lib/freadptr.c b/lib/freadptr.c index 3afa621..9176559 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 fd9da63..81f51ed 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 24a148a..79e7c38 100644 --- a/lib/fwritable.c +++ b/lib/fwritable.c @@ -25,6 +25,9 @@ # include <fcntl.h> #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 1821352..43ce3d6 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 <stdio_ext.h> # define fwritable(stream) (__fwritable (stream) != 0) diff --git a/lib/fwriting.c b/lib/fwriting.c index 9be6fb2..4ffa12d 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 f2a6c5e..42f7e94 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 <stdio_ext.h> # define fwriting(stream) (__fwriting (stream) != 0) diff --git a/lib/stdio-impl.h b/lib/stdio-impl.h index 7a0ac4d..393ef0c 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 + <https://android.googlesource.com/platform/bionic.git/+/f0141dfab10a4b332769d52fa76631a64741297a> + the innards of FILE were public, and fp_ub could be defined like for OpenBSD, + see <https://android.googlesource.com/platform/bionic.git/+/e78392637d5086384a5631ddfdfa8d7ec8326ee3/libc/stdio/fileext.h> + and <https://android.googlesource.com/platform/bionic.git/+/e78392637d5086384a5631ddfdfa8d7ec8326ee3/libc/stdio/local.h>. + 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 <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> - and <https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */ + and <https://cvsweb.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> + and <https://github.com/Stichting-MINIX-Research-Foundation/minix/blob/master/lib/libc/stdio/fileext.h> */ 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 + <https://android.googlesource.com/platform/bionic.git/+/e70e0e9267d069bf56a5078c99307e08a7280de7> */ +# 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