use unlocked I/O in getdelim
authorPaolo Bonzini <bonzini@gnu.org>
Wed, 27 Aug 2008 12:44:58 +0000 (14:44 +0200)
committerPaolo Bonzini <bonzini@gnu.org>
Wed, 27 Aug 2008 14:58:26 +0000 (16:58 +0200)
2008-08-27  Paolo Bonzini  <bonzini@gnu.org>

* lib/getdelim.c (flockfile, funlockfile): Make all of them
dummy if one is not available.  Do not touch them if
USE_UNLOCKED_IO, instead letting unlocked-io.h do that.
(getc_maybe_unlocked): New.
* m4/getdelim.m4 (gl_PREREQ_GETDELIM): Check for getc_unlocked.

ChangeLog
lib/getdelim.c
m4/getdelim.m4

index 1f25783a83b7091da1d1b4aefb64f669d59f0de8..0b3050d616e56b7a989b7d8cadd175bbc223f195 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-08-27  Paolo Bonzini  <bonzini@gnu.org>
+
+       * lib/getdelim.c (flockfile, funlockfile): Make all of them
+       dummy if one is not available.  Do not touch them if
+       USE_UNLOCKED_IO, instead letting unlocked-io.h do that.
+       (getc_maybe_unlocked): New.
+       * m4/getdelim.m4 (gl_PREREQ_GETDELIM): Check for getc_unlocked.
+
 2008-08-26  Eric Blake  <ebb9@byu.net>
 
        doc/INSTALL: resync from autoconf
index 2e127fcaaa2bf0e3dc934b1c1528444c26a74c4f..35cb2d873749a665fc5c432e39ca40884d173c55 100644 (file)
 #ifndef SSIZE_MAX
 # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
 #endif
-#if !HAVE_FLOCKFILE
+
+#if USE_UNLOCKED_IO
+# include "unlocked-io.h"
+# define getc_maybe_unlocked(fp)       getc(fp)
+#elif !HAVE_FLOCKFILE || !HAVE_FUNLOCKFILE || !HAVE_DECL_GETC_UNLOCKED
 # undef flockfile
-# define flockfile(x) ((void) 0)
-#endif
-#if !HAVE_FUNLOCKFILE
 # undef funlockfile
+# define flockfile(x) ((void) 0)
 # define funlockfile(x) ((void) 0)
+# define getc_maybe_unlocked(fp)       getc(fp)
+#else
+# define getc_maybe_unlocked(fp)       getc_unlocked(fp)
 #endif
 
 /* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
@@ -79,7 +84,7 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
     {
       int i;
 
-      i = getc (fp);
+      i = getc_maybe_unlocked (fp);
       if (i == EOF)
        {
          result = -1;
index 18b96bef85d547dc5cbe6279bc6ff5a80ffeea6f..7760f8279bd9b8df7ab5982781f656068454d5e6 100644 (file)
@@ -31,4 +31,5 @@ AC_DEFUN([gl_FUNC_GETDELIM],
 AC_DEFUN([gl_PREREQ_GETDELIM],
 [
   AC_CHECK_FUNCS([flockfile funlockfile])
+  AC_CHECK_DECLS([getc_unlocked])
 ])