stdioext: Add support for musl libc.
authorBruno Haible <bruno@clisp.org>
Tue, 19 Jun 2012 21:35:08 +0000 (23:35 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 19 Jun 2012 21:35:08 +0000 (23:35 +0200)
* m4/fbufmode.m4 (gl_FUNC_FBUFMODE): Test whether __fbufsize exists.
* lib/fbufmode.c (fbufmode): Add conditional code for musl.

* m4/fseterr.m4: New file.
* lib/fseterr.h (fseterr): Define as an alias of __fseterr if that
function exists.
* modules/fseterr (Files): Add m4/fseterr.m4.
(configure.ac): Invoke gl_FUNC_FSETERR. Compile fseterr.c if
__fseterr does not exist.
(Makefile.am): Remove fseterr.c from lib_SOURCES.

* lib/freadable.h: Update comment.

* lib/fwritable.h: Update comment.

* lib/freading.h: Update comment.

* lib/fwriting.h: Update comment.

* m4/freadahead.m4: New file.
* lib/freadahead.h (freadahead): Define as an alias of __freadahead if
that function exists.
* modules/freadahead (Files): Add m4/freadahead.m4.
(configure.ac): Invoke gl_FUNC_FREADAHEAD. Compile freadahead.c if
__freadahead does not exist.
(Makefile.am): Remove freadahead.c from lib_SOURCES.

* m4/freadptr.m4: New file.
* lib/freadptr.h (freadptr): Define as an alias of __freadptr if that
function exists.
* modules/freadptr (Files): Add m4/freadptr.m4.
(configure.ac): Invoke gl_FUNC_FREADPTR. Compile freadptr.c if
__freadptr does not exist.
(Makefile.am): Remove freadptr.c from lib_SOURCES.

* m4/freadseek.m4: New file.
* lib/freadseek.c (freadptrinc): Use __freadptrinc if that function
exists.
* modules/freadseek (Files): Add m4/freadseek.m4.
(configure.ac): Invoke gl_FUNC_FREADSEEK.

* lib/fpurge.c (fpurge): Update comment.

Reported by and with help from Rich Felker <dalias@aerifal.cx>.

20 files changed:
ChangeLog
lib/fbufmode.c
lib/fpurge.c
lib/freadable.h
lib/freadahead.h
lib/freading.h
lib/freadptr.h
lib/freadseek.c
lib/fseterr.h
lib/fwritable.h
lib/fwriting.h
m4/fbufmode.m4
m4/freadahead.m4 [new file with mode: 0644]
m4/freadptr.m4 [new file with mode: 0644]
m4/freadseek.m4 [new file with mode: 0644]
m4/fseterr.m4 [new file with mode: 0644]
modules/freadahead
modules/freadptr
modules/freadseek
modules/fseterr

index bf20750..999a357 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,54 @@
 2012-06-19  Bruno Haible  <bruno@clisp.org>
 
+       stdioext: Add support for musl libc.
+
+       * m4/fbufmode.m4 (gl_FUNC_FBUFMODE): Test whether __fbufsize exists.
+       * lib/fbufmode.c (fbufmode): Add conditional code for musl.
+
+       * m4/fseterr.m4: New file.
+       * lib/fseterr.h (fseterr): Define as an alias of __fseterr if that
+       function exists.
+       * modules/fseterr (Files): Add m4/fseterr.m4.
+       (configure.ac): Invoke gl_FUNC_FSETERR. Compile fseterr.c if
+       __fseterr does not exist.
+       (Makefile.am): Remove fseterr.c from lib_SOURCES.
+
+       * lib/freadable.h: Update comment.
+
+       * lib/fwritable.h: Update comment.
+
+       * lib/freading.h: Update comment.
+
+       * lib/fwriting.h: Update comment.
+
+       * m4/freadahead.m4: New file.
+       * lib/freadahead.h (freadahead): Define as an alias of __freadahead if
+       that function exists.
+       * modules/freadahead (Files): Add m4/freadahead.m4.
+       (configure.ac): Invoke gl_FUNC_FREADAHEAD. Compile freadahead.c if
+       __freadahead does not exist.
+       (Makefile.am): Remove freadahead.c from lib_SOURCES.
+
+       * m4/freadptr.m4: New file.
+       * lib/freadptr.h (freadptr): Define as an alias of __freadptr if that
+       function exists.
+       * modules/freadptr (Files): Add m4/freadptr.m4.
+       (configure.ac): Invoke gl_FUNC_FREADPTR. Compile freadptr.c if
+       __freadptr does not exist.
+       (Makefile.am): Remove freadptr.c from lib_SOURCES.
+
+       * m4/freadseek.m4: New file.
+       * lib/freadseek.c (freadptrinc): Use __freadptrinc if that function
+       exists.
+       * modules/freadseek (Files): Add m4/freadseek.m4.
+       (configure.ac): Invoke gl_FUNC_FREADSEEK.
+
+       * lib/fpurge.c (fpurge): Update comment.
+
+       Reported by and with help from Rich Felker <dalias@aerifal.cx>.
+
+2012-06-19  Bruno Haible  <bruno@clisp.org>
+
        *printf-posix: Put more info into config.log.
        * m4/printf.m4 (gl_PRINTF_ENOMEM): Emit conftest's error output and
        exit code into config.log.
index b48cdbb..b7a79e2 100644 (file)
@@ -79,6 +79,10 @@ fbufmode (FILE *fp)
   if (fp->__linebuf)
     return _IOLBF;
   return (fp->__bufsize > 0 ? _IOFBF : _IONBF);
+#elif HAVE___FLBF && HAVE___FBUFSIZE /* musl libc */
+  if (__flbf (fp))
+    return _IOLBF;
+  return (__fbufsize (fp) > 0 ? _IOFBF : _IONBF);
 #elif defined EPLAN9                /* Plan9 */
   if (fp->flags & 2 /* LINEBUF */)
     return _IOLBF;
index 24c28d8..a4bc667 100644 (file)
@@ -29,7 +29,7 @@
 int
 fpurge (FILE *fp)
 {
-#if HAVE___FPURGE                   /* glibc >= 2.2, Haiku, Solaris >= 7 */
+#if HAVE___FPURGE                   /* glibc >= 2.2, Haiku, Solaris >= 7, musl libc */
 
   __fpurge (fp);
   /* The __fpurge function does not have a return value.  */
index 9a6c454..84917b9 100644 (file)
@@ -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 */
+#if HAVE___FREADABLE /* glibc >= 2.2, Solaris >= 7, musl libc */
 
 # include <stdio_ext.h>
 # define freadable(stream) (__freadable (stream) != 0)
index d874602..49eb00d 100644 (file)
 #include <stddef.h>
 #include <stdio.h>
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /* Assuming the stream STREAM is open for reading:
    Return the number of bytes waiting in the input buffer of STREAM.
    This includes both the bytes that have been read from the underlying input
@@ -31,8 +27,21 @@ extern "C" {
 
    STREAM must not be wide-character oriented.  */
 
+#if HAVE___FREADAHEAD /* musl libc */
+
+# include <stdio_ext.h>
+# define freadahead(stream) __freadahead (stream)
+
+#else
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
 extern size_t freadahead (FILE *stream) _GL_ATTRIBUTE_PURE;
 
-#ifdef __cplusplus
+# ifdef __cplusplus
 }
+# endif
+
 #endif
index 9668d20..86316a5 100644 (file)
@@ -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  */
+/* Solaris >= 7, not glibc >= 2.2, but glibc >= 2.7, or musl libc  */
 
 # include <stdio_ext.h>
 # define freading(stream) (__freading (stream) != 0)
index 464bedb..c7d0acd 100644 (file)
 #include <stddef.h>
 #include <stdio.h>
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /* Assuming the stream STREAM is open for reading:
    Return a pointer to the input buffer of STREAM, or NULL.
    If the returned pointer is non-NULL, *SIZEP is set to the (positive) size
@@ -32,8 +28,21 @@ extern "C" {
 
    STREAM must not be wide-character oriented.  */
 
+#if HAVE___FREADPTR /* musl libc */
+
+# include <stdio_ext.h>
+# define freadptr(stream,sizep) __freadptr (stream, sizep)
+
+#else
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
 extern const char * freadptr (FILE *stream, size_t *sizep);
 
-#ifdef __cplusplus
+# ifdef __cplusplus
 }
+# endif
+
 #endif
index 4145173..92923b9 100644 (file)
@@ -34,7 +34,9 @@ static inline void
 freadptrinc (FILE *fp, size_t increment)
 {
   /* Keep this code in sync with freadptr!  */
-#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
+#if HAVE___FREADPTRINC              /* musl libc */
+  __freadptrinc (fp, increment);
+#elif 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;
index b3930c5..16a1afe 100644 (file)
 
 #include <stdio.h>
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
 /* Set the error indicator of the stream FP.
    The "error indicator" is set when an I/O operation on the stream fails, and
    is cleared (together with the "end-of-file" indicator) by clearerr (FP).  */
-extern void fseterr (FILE *fp);
 
+#if HAVE___FSETERR /* musl libc */
+
+# include <stdio_ext.h>
+# define fseterr(fp) __fseterr (fp)
 
-#ifdef __cplusplus
+#else
+
+# ifdef __cplusplus
+extern "C" {
+# endif
+
+extern void fseterr (FILE *fp);
+
+# ifdef __cplusplus
 }
+# endif
+
 #endif
 
 #endif /* _FSETERR_H */
index 9c95dbe..f5875f7 100644 (file)
@@ -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 */
+#if HAVE___FWRITABLE /* glibc >= 2.2, Solaris >= 7, musl libc */
 
 # include <stdio_ext.h>
 # define fwritable(stream) (__fwritable (stream) != 0)
index 07da49b..13415b9 100644 (file)
@@ -33,7 +33,7 @@
 
    STREAM must not be wide-character oriented.  */
 
-#if HAVE___FWRITING /* glibc >= 2.2, Solaris >= 7 */
+#if HAVE___FWRITING /* glibc >= 2.2, Solaris >= 7, musl libc */
 
 # include <stdio_ext.h>
 # define fwriting(stream) (__fwriting (stream) != 0)
index d9fbf46..247d393 100644 (file)
@@ -1,4 +1,4 @@
-# fbufmode.m4 serial 1
+# fbufmode.m4 serial 2
 dnl Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -7,5 +7,5 @@ dnl with or without modifications, as long as this notice is preserved.
 AC_DEFUN([gl_FUNC_FBUFMODE],
 [
   dnl Prerequisites of lib/fbufmode.c.
-  AC_CHECK_FUNCS_ONCE([__flbf])
+  AC_CHECK_FUNCS_ONCE([__flbf __fbufsize])
 ])
diff --git a/m4/freadahead.m4 b/m4/freadahead.m4
new file mode 100644 (file)
index 0000000..4eb6a4b
--- /dev/null
@@ -0,0 +1,10 @@
+# freadahead.m4 serial 1
+dnl Copyright (C) 2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_FREADAHEAD],
+[
+  AC_CHECK_FUNCS_ONCE([__freadahead])
+])
diff --git a/m4/freadptr.m4 b/m4/freadptr.m4
new file mode 100644 (file)
index 0000000..9836bef
--- /dev/null
@@ -0,0 +1,10 @@
+# freadptr.m4 serial 1
+dnl Copyright (C) 2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_FREADPTR],
+[
+  AC_CHECK_FUNCS_ONCE([__freadptr])
+])
diff --git a/m4/freadseek.m4 b/m4/freadseek.m4
new file mode 100644 (file)
index 0000000..6ab8392
--- /dev/null
@@ -0,0 +1,11 @@
+# freadseek.m4 serial 1
+dnl Copyright (C) 2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_FREADSEEK],
+[
+  AC_REQUIRE([AC_C_INLINE])
+  AC_CHECK_FUNCS_ONCE([__freadptrinc])
+])
diff --git a/m4/fseterr.m4 b/m4/fseterr.m4
new file mode 100644 (file)
index 0000000..3eb3197
--- /dev/null
@@ -0,0 +1,10 @@
+# fseterr.m4 serial 1
+dnl Copyright (C) 2012 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_FSETERR],
+[
+  AC_CHECK_FUNCS_ONCE([__fseterr])
+])
index 96ef2e8..dd50366 100644 (file)
@@ -6,13 +6,17 @@ Files:
 lib/freadahead.h
 lib/freadahead.c
 lib/stdio-impl.h
+m4/freadahead.m4
 
 Depends-on:
 
 configure.ac:
+gl_FUNC_FREADAHEAD
+if test $ac_cv_func___freadahead = no; then
+  AC_LIBOBJ([freadahead])
+fi
 
 Makefile.am:
-lib_SOURCES += freadahead.c
 
 Include:
 "freadahead.h"
index 5ae340e..00a9f3b 100644 (file)
@@ -5,13 +5,17 @@ Files:
 lib/freadptr.h
 lib/freadptr.c
 lib/stdio-impl.h
+m4/freadptr.m4
 
 Depends-on:
 
 configure.ac:
+gl_FUNC_FREADPTR
+if test $ac_cv_func___freadptr = no; then
+  AC_LIBOBJ([freadptr])
+fi
 
 Makefile.am:
-lib_SOURCES += freadptr.c
 
 Include:
 "freadptr.h"
index e1ad31c..0631b3b 100644 (file)
@@ -5,6 +5,7 @@ Files:
 lib/freadseek.h
 lib/freadseek.c
 lib/stdio-impl.h
+m4/freadseek.m4
 
 Depends-on:
 freadahead
@@ -13,7 +14,7 @@ fseeko
 lseek
 
 configure.ac:
-AC_REQUIRE([AC_C_INLINE])
+gl_FUNC_FREADSEEK
 
 Makefile.am:
 lib_SOURCES += freadseek.c
index 190cbd2..a48712e 100644 (file)
@@ -5,13 +5,17 @@ Files:
 lib/fseterr.h
 lib/fseterr.c
 lib/stdio-impl.h
+m4/fseterr.m4
 
 Depends-on:
 
 configure.ac:
+gl_FUNC_FSETERR
+if test $ac_cv_func___fseterr = no; then
+  AC_LIBOBJ([fseterr])
+fi
 
 Makefile.am:
-lib_SOURCES += fseterr.c
 
 Include:
 "fseterr.h"