summary refs log tree commit diff
path: root/argp
diff options
context:
space:
mode:
Diffstat (limited to 'argp')
-rw-r--r--argp/argp-fmtstream.c18
-rw-r--r--argp/argp-help.c54
2 files changed, 49 insertions, 23 deletions
diff --git a/argp/argp-fmtstream.c b/argp/argp-fmtstream.c
index 0c9b3118e2..e5acda68e6 100644
--- a/argp/argp-fmtstream.c
+++ b/argp/argp-fmtstream.c
@@ -1,5 +1,5 @@
 /* Word-wrapping and line-truncating streams
-   Copyright (C) 1997 Free Software Foundation, Inc.
+   Copyright (C) 1997, 1998 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Written by Miles Bader <miles@gnu.ai.mit.edu>.
 
@@ -40,6 +40,10 @@
 #define isblank(ch) ((ch)==' ' || (ch)=='\t')
 #endif
 
+#if defined _LIBC && defined USE_IN_LIBIO
+# define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a)
+#endif
+
 #define INIT_BUF_SIZE 200
 #define PRINTF_SIZE_GUESS 150
 
@@ -89,7 +93,7 @@ __argp_fmtstream_free (argp_fmtstream_t fs)
 {
   __argp_fmtstream_update (fs);
   if (fs->p > fs->buf)
-    fwrite (fs->buf, 1, fs->p - fs->buf, fs->stream);
+    fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
   free (fs->buf);
   free (fs);
 }
@@ -129,7 +133,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
 	      /* No buffer space for spaces.  Must flush.  */
 	      size_t i;
 	      for (i = 0; i < pad; i++)
-		putc (' ', fs->stream);
+		putc_unlocked (' ', fs->stream);
 	    }
 	  fs->point_col = pad;
 	}
@@ -262,8 +266,8 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
 	      /* Output the first line so we can use the space.  */
 	      {
 		if (nl > fs->buf)
-		  fwrite (fs->buf, 1, nl - fs->buf, fs->stream);
-		putc ('\n', fs->stream);
+		  fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream);
+		putc_unlocked ('\n', fs->stream);
 		len += buf - fs->buf;
 		nl = buf = fs->buf;
 	      }
@@ -279,7 +283,7 @@ __argp_fmtstream_update (argp_fmtstream_t fs)
 	      *nl++ = ' ';
 	  else
 	    for (i = 0; i < fs->wmargin; ++i)
-	      putc (' ', fs->stream);
+	      putc_unlocked (' ', fs->stream);
 
 	  /* Copy the tail of the original buffer into the current buffer
 	     position.  */
@@ -316,7 +320,7 @@ __argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount)
       /* Flush FS's buffer.  */
       __argp_fmtstream_update (fs);
 
-      wrote = fwrite (fs->buf, 1, fs->p - fs->buf, fs->stream);
+      wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
       if (wrote == fs->p - fs->buf)
 	{
 	  fs->p = fs->buf;
diff --git a/argp/argp-help.c b/argp/argp-help.c
index 09daa63068..246096943f 100644
--- a/argp/argp-help.c
+++ b/argp/argp-help.c
@@ -32,11 +32,16 @@
 
 #ifndef _
 /* This is for other GNU distributions with internationalized messages.  */
-#ifdef HAVE_LIBINTL_H
-# include <libintl.h>
-#else
-# define dgettext(domain, msgid) (msgid)
+# ifdef HAVE_LIBINTL_H
+#  include <libintl.h>
+# else
+#  define dgettext(domain, msgid) (msgid)
+# endif
 #endif
+
+#ifdef USE_IN_LIBIO
+# define flockfile(s) _IO_flockfile (s)
+# define funlockfile(s) _IO_funlockfile (s)
 #endif
 
 #include "argp.h"
@@ -1405,7 +1410,7 @@ argp_doc (const struct argp *argp, const struct argp_state *state,
     {
       if (inp_text_limit)
 	/* Copy INP_TEXT so that it's nul-terminated.  */
-	inp_text = strndup (inp_text, inp_text_limit);
+	inp_text = __strndup (inp_text, inp_text_limit);
       input = __argp_input (argp, state);
       text =
 	(*argp->help_filter) (post
@@ -1479,12 +1484,17 @@ _help (const struct argp *argp, const struct argp_state *state, FILE *stream,
   if (! stream)
     return;
 
+  flockfile (stream);
+
   if (! uparams.valid)
     fill_in_uparams (state);
 
   fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0);
   if (! fs)
-    return;
+    {
+      funlockfile (stream);
+      return;
+    }
 
   if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG))
     {
@@ -1590,6 +1600,8 @@ Try `%s --help' or `%s --usage' for more information.\n"),
       anything = 1;
     }
 
+  funlockfile (stream);
+
   if (hol)
     hol_free (hol);
 
@@ -1647,17 +1659,22 @@ __argp_error (const struct argp_state *state, const char *fmt, ...)
 	{
 	  va_list ap;
 
-	  fputs (state ? state->name : program_invocation_short_name, stream);
-	  putc (':', stream);
-	  putc (' ', stream);
+	  flockfile (stream);
+
+	  fputs_unlocked (state ? state->name : program_invocation_short_name,
+			  stream);
+	  putc_unlocked (':', stream);
+	  putc_unlocked (' ', stream);
 
 	  va_start (ap, fmt);
 	  vfprintf (stream, fmt, ap);
 	  va_end (ap);
 
-	  putc ('\n', stream);
+	  putc_unlocked ('\n', stream);
 
 	  __argp_state_help (state, stream, ARGP_HELP_STD_ERR);
+
+	  funlockfile (stream);
 	}
     }
 }
@@ -1683,14 +1700,17 @@ __argp_failure (const struct argp_state *state, int status, int errnum,
 
       if (stream)
 	{
-	  fputs (state ? state->name : program_invocation_short_name, stream);
+	  flockfile (stream);
+
+	  fputs_unlocked (state ? state->name : program_invocation_short_name,
+			  stream);
 
 	  if (fmt)
 	    {
 	      va_list ap;
 
-	      putc (':', stream);
-	      putc (' ', stream);
+	      putc_unlocked (':', stream);
+	      putc_unlocked (' ', stream);
 
 	      va_start (ap, fmt);
 	      vfprintf (stream, fmt, ap);
@@ -1699,12 +1719,14 @@ __argp_failure (const struct argp_state *state, int status, int errnum,
 
 	  if (errnum)
 	    {
-	      putc (':', stream);
-	      putc (' ', stream);
+	      putc_unlocked (':', stream);
+	      putc_unlocked (' ', stream);
 	      fputs (strerror (errnum), stream);
 	    }
 
-	  putc ('\n', stream);
+	  putc_unlocked ('\n', stream);
+
+	  funlockfile (stream);
 
 	  if (status && (!state || !(state->flags & ARGP_NO_EXIT)))
 	    exit (status);