fflush, freadahead, fseeko: Fix for Android
authorKevin Cernekee <cernekee@gmail.com>
Sat, 7 Sep 2013 03:00:38 +0000 (20:00 -0700)
committerPádraig Brady <P@draigBrady.com>
Thu, 19 Sep 2013 19:05:17 +0000 (20:05 +0100)
* lib/stdio-impl.h: Use local __sfileext definition.

Suggested by Bruno Haible in:
<http://lists.gnu.org/archive/html/bug-gnulib/2012-01/msg00306.html>

fflush, freadahead, and fseeko have trouble compiling on Android[1]
because they need access to internal elements of the FILE struct.
Bionic libc[2], like OpenBSD libc[3], puts the ungetc buffer "_ub"
at the beginning of the __sfileext struct.  Therefore we can reuse the
existing OpenBSD implementation for Android.

Test results (Android 4.2.2, ARMv7, NDK r9):

    root@android:/data/local/tmp # export srcdir=`pwd`
    root@android:/data/local/tmp # ./test-fflush2.sh ; echo $?
    0
    root@android:/data/local/tmp # ./test-freadahead.sh ; echo $?
    0
    root@android:/data/local/tmp # ./test-fseeko.sh ; echo $?
    0
    root@android:/data/local/tmp # ./test-fseeko2.sh ; echo $?
    Skipping test: ungetc cannot handle arbitrary bytes
    77
    root@android:/data/local/tmp # ./test-fseeko3.sh ; echo $?
    0
    root@android:/data/local/tmp # ./test-fseeko4.sh ; echo $?
    0

[1] http://lists.gnu.org/archive/html/bug-gnulib/2012-01/msg00295.html
[2] https://android.googlesource.com/platform/bionic/+/android-4.3_r2.2/libc/stdio/fileext.h
[3] http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=1.2;content-type=text%2Fplain

ChangeLog
lib/stdio-impl.h

index b58a877..a467bbe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-09-17  Kevin Cernekee  <cernekee@gmail.com>
+
+       fflush, freadahead, fseeko: Fix for Android
+       Suggested by Bruno Haible in:
+       <http://lists.gnu.org/archive/html/bug-gnulib/2012-01/msg00306.html>
+       * lib/stdio-impl.h: Use local __sfileext definition.
+
 2013-09-17  Mats Erik Andersson  <gnu@gisladisker.se>
 
        pmccabe2html: Portability to other awk versions.
index e00600a..45291cf 100644 (file)
@@ -57,7 +57,7 @@
 #  define fp_ fp
 # endif
 
-# if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ /* NetBSD >= 1.5ZA, OpenBSD */
+# if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ || defined __ANDROID__ /* NetBSD >= 1.5ZA, OpenBSD, Android */
   /* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
      and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
   struct __sfileext