/* 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>.
#define isblank(ch) ((ch)==' ' || (ch)=='\t')
#endif
+#if defined _LIBC && defined USE_IN_LIBIO
+# include <libio/libioP.h>
+# define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a)
+#endif
+
#define INIT_BUF_SIZE 200
#define PRINTF_SIZE_GUESS 150
\f
{
__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);
}
/* 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;
}
the end of the buffer. */
nl = fs->p;
}
- else if (fs->point_col + (nl - buf) < fs->rmargin)
+ else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin)
{
/* The buffer contains a full line that fits within the maximum
line width. Reset point and scan the next line. */
/* 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;
}
*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. */
int
__argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount)
{
- if (fs->end - fs->p < amount)
+ if ((size_t) (fs->end - fs->p) < amount)
{
ssize_t wrote;
/* 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;
return 0;
}
- if (fs->end - fs->buf < amount)
+ if ((size_t) (fs->end - fs->buf) < amount)
/* Gotta grow the buffer. */
{
size_t new_size = fs->end - fs->buf + amount;
ssize_t
__argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...)
{
- size_t out;
+ int out;
size_t size_guess = PRINTF_SIZE_GUESS; /* How much space to reserve. */
do