summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2012-06-19 23:35:08 +0200
committerBruno Haible <bruno@clisp.org>2012-06-19 23:35:08 +0200
commit2b14f42b44f04bce5631269ed46cd8be2413ccec (patch)
tree429bada82d83dc604d674a02cb621cb00494a3e8 /lib
parent81c71120400c0f49c1429bf4b5d5ad89c151123a (diff)
downloadgnulib-2b14f42b44f04bce5631269ed46cd8be2413ccec.tar.gz
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>.
Diffstat (limited to 'lib')
-rw-r--r--lib/fbufmode.c4
-rw-r--r--lib/fpurge.c2
-rw-r--r--lib/freadable.h2
-rw-r--r--lib/freadahead.h19
-rw-r--r--lib/freading.h2
-rw-r--r--lib/freadptr.h19
-rw-r--r--lib/freadseek.c4
-rw-r--r--lib/fseterr.h22
-rw-r--r--lib/fwritable.h2
-rw-r--r--lib/fwriting.h2
10 files changed, 55 insertions, 23 deletions
diff --git a/lib/fbufmode.c b/lib/fbufmode.c
index b48cdbb387..b7a79e2c31 100644
--- a/lib/fbufmode.c
+++ b/lib/fbufmode.c
@@ -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;
diff --git a/lib/fpurge.c b/lib/fpurge.c
index 24c28d843c..a4bc667125 100644
--- a/lib/fpurge.c
+++ b/lib/fpurge.c
@@ -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. */
diff --git a/lib/freadable.h b/lib/freadable.h
index 9a6c454f56..84917b96ab 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 */
+#if HAVE___FREADABLE /* glibc >= 2.2, Solaris >= 7, musl libc */
# include <stdio_ext.h>
# define freadable(stream) (__freadable (stream) != 0)
diff --git a/lib/freadahead.h b/lib/freadahead.h
index d87460243d..49eb00df69 100644
--- a/lib/freadahead.h
+++ b/lib/freadahead.h
@@ -17,10 +17,6 @@
#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
diff --git a/lib/freading.h b/lib/freading.h
index 9668d20232..86316a5be8 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 */
+/* Solaris >= 7, 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.h b/lib/freadptr.h
index 464bedb731..c7d0acd237 100644
--- a/lib/freadptr.h
+++ b/lib/freadptr.h
@@ -17,10 +17,6 @@
#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
diff --git a/lib/freadseek.c b/lib/freadseek.c
index 4145173e9e..92923b923a 100644
--- a/lib/freadseek.c
+++ b/lib/freadseek.c
@@ -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;
diff --git a/lib/fseterr.h b/lib/fseterr.h
index b3930c5a88..16a1afeeae 100644
--- a/lib/fseterr.h
+++ b/lib/fseterr.h
@@ -19,19 +19,27 @@
#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 */
diff --git a/lib/fwritable.h b/lib/fwritable.h
index 9c95dbe2ca..f5875f789c 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 */
+#if HAVE___FWRITABLE /* glibc >= 2.2, Solaris >= 7, musl libc */
# include <stdio_ext.h>
# define fwritable(stream) (__fwritable (stream) != 0)
diff --git a/lib/fwriting.h b/lib/fwriting.h
index 07da49b6aa..13415b9152 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 */
+#if HAVE___FWRITING /* glibc >= 2.2, Solaris >= 7, musl libc */
# include <stdio_ext.h>
# define fwriting(stream) (__fwriting (stream) != 0)