+/* Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA. */
+
#include "libioP.h"
#include "stdio.h"
void
-clearerr(fp)
- FILE* fp;
+clearerr (fp)
+ FILE *fp;
{
- CHECK_FILE(fp, /*nothing*/);
- _IO_clearerr(fp);
+ CHECK_FILE (fp, /*nothing*/);
+ flockfile (fp);
+ _IO_clearerr (fp);
+ funlockfile (fp);
}
+
+#ifdef _IO_MTSAFE_IO
+weak_alias (clearerr, clearerr_locked)
+#endif
-/*
-Copyright (C) 1993, 1995 Free Software Foundation
+/* Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
ferror (fp)
_IO_FILE* fp;
{
+ int result;
CHECK_FILE (fp, EOF);
- return _IO_ferror (fp);
+ _IO_flockfile (fp);
+ result = _IO_ferror_unlocked (fp);
+ _IO_funlockfile (fp);
+ return result;
}
+
+#ifdef _IO_MTSAFE_IO
+
+weak_alias (ferror, ferror_locked)
+#endif
/*
-Copyright (C) 1993, 1995 Free Software Foundation
+Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
return _IO_fileno (fp);
}
+
+#ifdef _IO_MTSAFE_IO
+/* The fileno implementation for libio does not require locking because
+ it only accesses once a single variable and this is already atomic
+ (at least at thread level). */
+
+weak_alias (fileno_unlocked, fileno)
+weak_alias (fileno_locked, fileno)
+#endif
/*
-Copyright (C) 1993 Free Software Foundation
+Copyright (C) 1993, 1996 Free Software Foundation, Inc.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
int c;
_IO_FILE *fp;
{
+ int result;
CHECK_FILE (fp, EOF);
- return _IO_putc (c, fp);
+ _IO_flockfile (fp);
+ result = _IO_putc_unlocked (c, fp);
+ _IO_funlockfile (fp);
+ return result;
}
/*
-Copyright (C) 1993, 1995 Free Software Foundation
+Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
const char* mode;
FILE* fp;
{
+ FILE *result;
CHECK_FILE (fp, NULL);
if (!(fp->_flags & _IO_IS_FILEBUF))
return NULL;
- return _IO_freopen (filename, mode, fp);
+ flockfile (fp);
+ result = _IO_freopen (filename, mode, fp);
+ funlockfile (fp);
+ return result;
}
long int offset;
int whence;
{
+ int result;
CHECK_FILE (fp, -1);
- return _IO_fseek (fp, offset, whence);
+ flockfile (fp);
+ result = _IO_fseek (fp, offset, whence);
+ funlockfile (fp);
+ return result;
}
fp->_IO_save_end = NULL;
fp->_markers = NULL;
fp->_cur_column = 0;
+#ifdef _IO_MTSAFE_IO
+ _IO_mutex_init (fp->_lock);
+#endif
}
int
fp->_IO_save_base = NULL;
}
+#ifdef _IO_MTSAFE_IO
+ _IO_mutex_destroy (fp->_lock);
+#endif
+
_IO_un_link(fp);
}
/*
-Copyright (C) 1993, 1995 Free Software Foundation
+Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
#undef getc
int
-getc (stream)
- FILE *stream;
+getc (fp)
+ FILE *fp;
{
- return _IO_getc (stream);
+ int result;
+ CHECK_FILE (fp, EOF);
+ _IO_flockfile (fp);
+ result = _IO_getc_unlocked (fp);
+ _IO_funlockfile (fp);
+ return result;
}
+
+#ifdef _IO_MTSAFE_IO
+# undef getc_locked
+
+weak_alias (getc_locked, getc)
+#endif
/*
-Copyright (C) 1993 Free Software Foundation
+Copyright (C) 1993, 1996 Free Software Foundation, Inc.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
int
getchar ()
{
- return _IO_getc (stdin);
+ int result;
+ _IO_flockfile (stdin);
+ result = _IO_getc_unlocked (stdin);
+ _IO_funlockfile (stdin);
+ return result;
}
+
+#ifdef _IO_MTSAFE_IO
+# undef getchar_locked
+
+weak_alias (getchar_locked, getchar)
+#endif
CHECK_FILE(fp, EOF);
+ _IO_flockfile (fp);
if (fp->_IO_file_flags & _IO_IS_FILEBUF)
status = _IO_file_close_it (fp);
else
fp->_IO_file_flags = 0;
free(fp);
}
+ _IO_funlockfile (fp);
return status;
}
return _IO_flush_all ();
else
{
+ int result;
+ _IO_flockfile (fp);
CHECK_FILE (fp, EOF);
- return _IO_SYNC (fp) ? EOF : 0;
+ result = _IO_SYNC (fp) ? EOF : 0;
+ _IO_funlockfile (fp);
+ return result;
}
}
weak_alias (_IO_fflush, fflush)
+
+#ifdef _IO_MTSAFE_IO
+weak_alias (_IO_fflush, fflush_locked)
+#endif
{
_IO_fpos_t pos;
CHECK_FILE (fp, EOF);
+ _IO_flockfile (fp);
pos = _IO_seekoff (fp, 0, _IO_seek_cur, 0);
+ _IO_funlockfile (fp);
if (pos == _IO_pos_BAD)
{
#ifdef EIO
_IO_FILE* fp;
{
_IO_size_t count;
+ char *result;
CHECK_FILE (fp, NULL);
if (n <= 0)
return NULL;
+ _IO_flockfile (fp);
count = _IO_getline (fp, buf, n - 1, '\n', 1);
if (count == 0 || (fp->_IO_file_flags & _IO_ERR_SEEN))
- return NULL;
- buf[count] = 0;
- return buf;
+ result = NULL;
+ else
+ {
+ buf[count] = '\0';
+ result = buf;
+ }
+ _IO_funlockfile (fp);
+ return result;
}
weak_alias (_IO_fgets, fgets)
/*
-Copyright (C) 1993 Free Software Foundation
+Copyright (C) 1993, 1996 Free Software Foundation, Inc.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
_IO_FILE *fp;
{
_IO_size_t len = strlen (str);
+ int result;
CHECK_FILE (fp, EOF);
- if (_IO_sputn( fp, str, len) != len)
- return EOF;
- return 1;
+ _IO_flockfile (fp);
+ if (_IO_sputn (fp, str, len) != len)
+ result = EOF;
+ else
+ result = 1;
+ _IO_funlockfile (fp);
+ return result;
}
weak_alias (_IO_fputs, fputs)
CHECK_FILE (fp, 0);
if (bytes_requested == 0)
return 0;
+ _IO_flockfile (fp);
bytes_read = _IO_sgetn (fp, (char *) buf, bytes_requested);
+ _IO_funlockfile (fp);
return bytes_requested == bytes_read ? count : bytes_read / size;
}
weak_alias (_IO_fread, fread)
_IO_FILE* fp;
const _IO_fpos_t *posp;
{
+ int result;
CHECK_FILE (fp, EOF);
+ _IO_flockfile (fp);
if (_IO_seekpos (fp, *posp, _IOS_INPUT|_IOS_OUTPUT) == _IO_pos_BAD)
{
/*ANSI explicily requires setting errno to a positive value on failure.*/
if (errno == 0)
errno = EIO;
#endif
- return EOF;
+ result = EOF;
}
- return 0;
+ else
+ result = 0;
+ _IO_funlockfile (fp);
+ return result;
}
weak_alias (_IO_fsetpos, fsetpos)
{
_IO_pos_t pos;
CHECK_FILE (fp, -1L);
+ _IO_flockfile (fp);
pos = _IO_seekoff (fp, 0, _IO_seek_cur, 0);
+ _IO_funlockfile (fp);
if (pos == _IO_pos_BAD)
{
#ifdef EIO
CHECK_FILE (fp, 0);
if (request == 0)
return 0;
+ _IO_flockfile (fp);
written = _IO_sputn (fp, (const char *) buf, request);
+ _IO_funlockfile (fp);
/* Many traditional implementations return 0 if size==0 && count > 0,
but ANSI seems to require us to return count in this case. */
if (written == request)
int delimiter;
_IO_FILE *fp;
{
+ int result;
register _IO_ssize_t cur_len = 0;
_IO_ssize_t len;
return -1;
}
CHECK_FILE (fp, -1);
- if (_IO_ferror (fp))
- return -1;
+ _IO_flockfile (fp);
+ if (_IO_ferror_unlocked (fp))
+ {
+ result = -1;
+ goto unlock_return;
+ }
if (*lineptr == NULL || *n == 0)
{
*n = 120;
*lineptr = (char *) malloc (*n);
if (*lineptr == NULL)
- return -1;
+ {
+ result = -1;
+ goto unlock_return;
+ }
}
len = fp->_IO_read_end - fp->_IO_read_ptr;
if (len <= 0)
{
if (__underflow (fp) == EOF)
- return -1;
+ {
+ result = -1;
+ goto unlock_return;
+ }
len = fp->_IO_read_end - fp->_IO_read_ptr;
}
*n = needed;
*lineptr = (char *) realloc (*lineptr, needed);
if (*lineptr == NULL)
- return -1;
+ {
+ result = -1;
+ goto unlock_return;
+ }
}
memcpy (*lineptr + cur_len, (void *) fp->_IO_read_ptr, len);
fp->_IO_read_ptr += len;
len = fp->_IO_read_end - fp->_IO_read_ptr;
}
(*lineptr)[cur_len] = '\0';
- return cur_len;
+ result = cur_len;
+
+unlock_return:
+ _IO_funlockfile (fp);
+ return result;
}
weak_alias (_IO_getdelim, __getdelim)
char* buf;
{
_IO_size_t count;
- int ch = _IO_getc (_IO_stdin);
+ int ch;
+
+ _IO_flockfile (_IO_stdin);
+ ch = _IO_getc_unlocked (_IO_stdin);
if (ch == EOF)
return NULL;
if (ch == '\n')
if (_IO_stdin->_IO_file_flags & _IO_ERR_SEEN)
return NULL;
}
+ _IO_funlockfile (_IO_stdin);
buf[count] = 0;
return buf;
}
-/* Copyright (C) 1993 Free Software Foundation
+/* Copyright (C) 1993, 1996 Free Software Foundation, Inc.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
_IO_puts (str)
const char *str;
{
+ int result;
_IO_size_t len = strlen (str);
- if (_IO_sputn (_IO_stdout, str, len) != len)
- return EOF;
- if (_IO_putc ('\n', _IO_stdout) == EOF)
- return EOF;
- return len+1;
+ _IO_flockfile (fp);
+ if (_IO_sputn (_IO_stdout, str, len) == len
+ && _IO_putc_unlocked ('\n', _IO_stdout) != EOF)
+ result = len + 1;
+ else
+ result = EOF;
+ _IO_funlockfile (fp);
+ return result;
}
weak_alias (_IO_puts, puts)
/*
-Copyright (C) 1993 Free Software Foundation
+Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
_IO_size_t size;
{
CHECK_FILE (fp, );
+ _IO_flockfile (fp);
fp->_flags &= ~_IO_LINE_BUF;
if (!buf)
size = 0;
(void) _IO_SETBUF (fp, buf, size);
+ _IO_funlockfile (fp);
}
+
+weak_alias (_IO_setbuffer, setbuffer)
int mode;
_IO_size_t size;
{
+ int result;
CHECK_FILE (fp, EOF);
+ _IO_flockfile (fp);
switch (mode)
{
case _IOFBF:
A possibly cleaner alternative would be to add an
extra flag, but then flags are a finite resource. */
if (_IO_DOALLOCATE (fp) < 0)
- return EOF;
+ {
+ result = EOF;
+ goto unlock_return;
+ }
fp->_IO_file_flags &= ~_IO_LINE_BUF;
}
- return 0;
+ result = 0;
+ goto unlock_return;
}
break;
case _IOLBF:
fp->_IO_file_flags |= _IO_LINE_BUF;
if (buf == NULL)
- return 0;
+ {
+ result = 0;
+ goto unlock_return;
+ }
break;
case _IONBF:
buf = NULL;
size = 0;
break;
default:
- return EOF;
+ result = EOF;
+ goto unlock_return;
}
- return _IO_SETBUF (fp, buf, size) == NULL ? EOF : 0;
+ result = _IO_SETBUF (fp, buf, size) == NULL ? EOF : 0;
+unlock_return:
+ _IO_funlockfile (fp);
+ return result;
}
weak_alias (_IO_setvbuf, setvbuf)
/*
-Copyright (C) 1993 Free Software Foundation
+Copyright (C) 1993, 1996 Free Software Foundation, Inc.
This file is part of the GNU IO Library. This library is free
software; you can redistribute it and/or modify it under the
int c;
_IO_FILE *fp;
{
+ int result;
CHECK_FILE (fp, EOF);
if (c == EOF)
return EOF;
- return _IO_sputbackc (fp, (unsigned char) c);
+ _IO_flockfile (fp);
+ result = _IO_sputbackc (fp, (unsigned char) c);
+ _IO_funlockfile (fp);
+ return result;
}
weak_alias (_IO_ungetc, ungetc)
_IO_JUMPS ((_IO_FILE *) &sf) = &_IO_str_jumps;
_IO_str_init_static ((_IO_FILE *) &sf, string, -1, string);
ret = _IO_vfprintf ((_IO_FILE *) &sf, format, args);
- _IO_putc('\0', (_IO_FILE *) &sf);
+ _IO_putc_unlocked ('\0', (_IO_FILE *) &sf);
return ret;
}
int (*close) __P ((struct _IO_FILE *));
} _IO_cookie_io_functions_t;
+/* Handle lock. */
+#ifdef _IO_MTSAFE_IO
+typedef pthread_mutex_t _IO_lock_t;
+#else
+typedef void _IO_lock_t;
+#endif
-/* The reentrant version of the libio implementation needs a semaphore for
- each _IO_FILE struture. Because we don't know how the semaphore
- will be implemented we try to be very general. */
-struct _IO_lock_t {
- void *ptr;
- short int field1;
- short int field2;
-};
/* A streammarker remembers a position in a buffer. */
/* char* _save_gptr; char* _save_egptr; */
- struct _IO_lock_t _IO_lock;
+ _IO_lock_t *_lock;
};
#ifndef __cplusplus
extern int __uflow __P((_IO_FILE*));
extern int __overflow __P((_IO_FILE*, int));
-#define _IO_getc(_fp) \
+#define _IO_getc_unlocked(_fp) \
((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end ? __uflow(_fp) \
: *(unsigned char*)(_fp)->_IO_read_ptr++)
-#define _IO_peekc(_fp) \
+#define _IO_peekc_unlocked(_fp) \
((_fp)->_IO_read_ptr >= (_fp)->_IO_read_end \
&& __underflow(_fp) == EOF ? EOF \
: *(unsigned char*)(_fp)->_IO_read_ptr)
-#define _IO_putc(_ch, _fp) \
+#define _IO_putc_unlocked(_ch, _fp) \
(((_fp)->_IO_write_ptr >= (_fp)->_IO_write_end) \
? __overflow(_fp, (unsigned char)(_ch)) \
: (unsigned char)(*(_fp)->_IO_write_ptr++ = (_ch)))
-#define _IO_feof(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
-#define _IO_ferror(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
+#define _IO_feof_unlocked(__fp) (((__fp)->_flags & _IO_EOF_SEEN) != 0)
+#define _IO_ferror_unlocked(__fp) (((__fp)->_flags & _IO_ERR_SEEN) != 0)
/* This one is for Emacs. */
#define _IO_PENDING_OUTPUT_COUNT(_fp) \
((_fp)->_IO_write_ptr - (_fp)->_IO_write_base)
+extern int _IO_getc_locked __P ((_IO_FILE *));
+extern int _IO_putc_locked __P ((int, _IO_FILE *));
+
+extern void _IO_flockfile __P ((_IO_FILE *));
+extern void _IO_funlockfile __P ((_IO_FILE *));
+
+#if !defined(_REENTRANT) && !defined(_THREAD_SAFE)
+# define _IO_flockfile(FILE) /**/
+# define _IO_funlockfile(FILE) /**/
+#endif /* _REENTRANT || _THREAD_SAFE */
+
+
extern int _IO_vfscanf __P((_IO_FILE*, const char*, _IO_va_list, int*));
extern int _IO_vfprintf __P((_IO_FILE*, const char*, _IO_va_list));
extern _IO_ssize_t _IO_padn __P((_IO_FILE *, int, _IO_ssize_t));
-/* Copyright (C) 1991, 1995 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
#undef putc
int
-putc (c, stream)
+putc (c, fp)
int c;
- _IO_FILE *stream;
+ _IO_FILE *fp;
{
- return _IO_putc (c, stream);
+ int result;
+ CHECK_FILE (fp, EOF);
+ _IO_flockfile (fp);
+ result = _IO_putc_unlocked (c, fp);
+ _IO_funlockfile (fp);
+ return result;
}
+
+#ifdef _IO_MTSAFE_IO
+# undef putc_locked
+
+weak_alias (putc_locked, putc)
+#endif
-/* Copyright (C) 1991, 1995 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
putchar (c)
int c;
{
- return _IO_putc (c, stdout);
+ int result;
+ _IO_flockfile (_IO_stdout);
+ result = _IO_putc_unlocked (c, _IO_stdout);
+ _IO_funlockfile (_IO_stdout);
+ return result;
}
+
+#ifdef _IO_MTSAFE_IO
+# undef putchar_locked
+
+weak_alias (putchar_locked, putchar)
+#endif
_IO_FILE* fp;
{
CHECK_FILE (fp, );
+ _IO_flockfile (fp);
_IO_rewind (fp);
+ _IO_funlockfile (fp);
}
#ifdef __USE_GNU
extern _IO_ssize_t getdelim __P ((char **, size_t *, int, FILE*));
extern _IO_ssize_t getline __P ((char **, size_t *, FILE *));
+extern _IO_ssize_t __getline __P ((char **, size_t *, FILE *));
extern int snprintf __P ((char *, size_t, __const char *, ...));
extern int __snprintf __P ((char *, size_t, __const char *, ...));
extern int __underflow __P ((struct _IO_FILE*));
extern int __overflow __P ((struct _IO_FILE*, int));
-#define getc(fp) _IO_getc (fp)
-#define putc(c, fp) _IO_putc (c, fp)
-#define putchar(c) putc (c, stdout)
-#define getchar() getc (stdin)
-
#ifdef __USE_BSD
extern int sys_nerr;
extern const char *const sys_errlist[];
extern const char *const _sys_errlist[];
#endif
+/* Handle locking of streams. */
+#if defined(_REENTRANT) || defined(_THREAD_SAFE)
+extern void clearerr_unlocked __P ((FILE *));
+extern void fileno_unlocked __P ((FILE *));
+extern void flockfile __P ((FILE *));
+extern void funlockfile __P ((FILE *));
+extern int fclose_unlocked __P ((FILE *));
+extern int fflush_unlocked __P ((FILE *));
+extern size_t fread_unlocked __P ((void *, size_t, size_t, FILE *));
+extern size_t fwrite_unlocked __P ((const void *, size_t, size_t, FILE *));
+
+# define getc_unlocked(fp) _IO_getc_unlocked (fp)
+# define getc_locked(fp) _IO_fgetc (fp)
+# define getchar_unlocked() getc_unlocked (stdin)
+# define getchar_locked() getc_locked (stdin)
+# define getc(fp) getc_locked (fp)
+
+# define putc_unlocked(c, fp) _IO_putc_unlocked (c, fp)
+# define putc_locked(c, fp) _IO_putc_locked (c, fp)
+# define putchar_unlocked(c) putc_unlocked (c, stdout)
+# define putchar_locked(c) putc_locked (c, stdout)
+# define putc(c, fp) putc_locked (c, fp)
+
+# define feof_unlocked(fp) _IO_feof_unlocked (fp)
+# define ferror_unlocked(fp) _IO_ferror_unlocked (fp)
+
+#else
+# define getc(fp) _IO_getc_unlocked (fp)
+# define putc(c, fp) _IO_putc_unlocked (c, fp)
+
+#endif /* _REENTRANT || _THREAD_SAFE */
+
+#define flockfile(FILE) _IO_flockfile (FILE)
+#define funlockfile(FILE) _IO_funlockfile (FILE)
+
+#define putchar(c) putc (c, stdout)
+#define getchar() getc (stdin)
+
+
#ifdef __cplusplus
}
#endif
+
+
#endif /* !_STDIO_H */
/* We use this file GNU C library and GNU I/O library. So make
names equal. */
# undef putc
-# define putc(c, f) _IO_putc (c, f)
+# define putc(c, f) _IO_putc_unlocked (c, f)
# define size_t _IO_size_t
# define FILE _IO_FILE
#else /* ! USE_IN_LIBIO */
# define ISDIGIT(Ch) iswdigit (Ch)
# ifdef USE_IN_LIBIO
-# define PUT(F, S, N) _IO_sputn (F, S, N)
-# define PAD(Padchar) \
+# define PUT(F, S, N) _IO_sputn (F, S, N)
+# define PAD(Padchar) \
if (width > 0) \
done += _IO_wpadn (s, Padchar, width)
# else
# define PUTC(C, F) wputc (C, F)
ssize_t __wprintf_pad __P ((FILE *, wchar_t pad, size_t n));
-# define PAD(Padchar) \
+# define PAD(Padchar) \
if (width > 0) \
{ if (__wprintf_pad (s, Padchar, width) == -1) \
return -1; else done += width; }
#ifdef USE_IN_LIBIO
/* This code is for use in libio. */
# include <libioP.h>
-# define PUTC(C, F) _IO_putc (C, F)
+# define PUTC(C, F) _IO_putc_unlocked (C, F)
# define vfprintf _IO_vfprintf
# define size_t _IO_size_t
# define FILE _IO_FILE
} \
} while (0)
# define UNBUFFERED_P(S) ((S)->_IO_file_flags & _IO_UNBUFFERED)
+# define flockfile(S) _IO_flockfile (S)
+# define fUNlockfile(S) _IO_funlockfile (S)
#else /* ! USE_IN_LIBIO */
/* This code is for use in the GNU C library. */
# include <stdio.h>
/* Find the first format specifier. */
f = lead_str_end = find_spec (format, &mbstate);
+ /* Lock stream. */
+ flockfile (s);
+
/* Write the literal text before the first format. */
outstring ((const UCHAR_T *) format,
lead_str_end - (const UCHAR_T *) format);
/* If we only have to print a simple string, return now. */
if (*f == L_('\0'))
- return done;
+ {
+ funlockfile (s);
+ return done;
+ }
/* Process whole format string. */
do
LABEL (form_unknown):
if (spec == L_('\0'))
- /* The format string ended before the specifier is complete. */
- return -1;
+ {
+ /* The format string ended before the specifier is complete. */
+ funlockfile (s);
+ return -1;
+ }
/* If we are in the fast loop force entering the complicated
one. */
}
while (*f != L_('\0'));
+ /* Unlock stream. */
+ funlockfile (s);
+
/* We processed the whole format without any positional parameters. */
return done;
/* If an error occured we don't have information about #
of chars. */
if (function_done < 0)
- return -1;
+ {
+ funlockfile (s);
+ return -1;
+ }
done += function_done;
}
}
}
+ /* Unlock the stream. */
+ funlockfile (s);
+
return done;
}
_IO_size_t written = _IO_sputn (target, s->_IO_write_base, used);
s->_IO_write_ptr -= written;
}
- return _IO_putc (c, s);
+ return PUTC (c, s);
}
static const struct _IO_jump_t _IO_helper_jumps =
# define va_list _IO_va_list
# define ungetc(c, s) _IO_ungetc (c, s)
-# define inchar() ((c = _IO_getc (s)), (void) ++read_in, c)
-# define conv_error() return ((void) (errp != NULL && (*errp |= 2)), \
- (void) (c == EOF || _IO_ungetc (c, s)), done)
-
-# define input_error() return ((void) (errp != NULL && (*errp |= 1)), \
- done == 0 ? EOF : done)
-# define memory_error() return ((void) (errno = ENOMEM), EOF)
-# define ARGCHECK(s, format) \
- do \
- { \
- /* Check file argument for consistence. */ \
- CHECK_FILE (s, -1); \
- if (s->_flags & _IO_NO_READS || format == NULL) \
- { \
- MAYBE_SET_EINVAL; \
- return -1; \
- } \
+# define inchar() ((c = _IO_getc_unlocked (s)), (void) ++read_in, c)
+# define conv_error() do { \
+ if (errp != NULL) *errp |= 2; \
+ if (c != EOF) _IO_ungetc (c, s); \
+ _IO_funlockfile (s); \
+ return done; \
+ } while (0)
+# define input_error() do { \
+ _IO_funlockfile (s); \
+ if (errp != NULL) *errp |= 1; \
+ return done ?: EOF; \
+ } while (0)
+# define memory_error() do { \
+ _IO_funlockfile (s); \
+ errno = ENOMEM; \
+ return EOF; \
+ } while (0)
+# define ARGCHECK(s, format) \
+ do \
+ { \
+ /* Check file argument for consistence. */ \
+ CHECK_FILE (s, EOF); \
+ if (s->_flags & _IO_NO_READS || format == NULL) \
+ { \
+ MAYBE_SET_EINVAL; \
+ return EOF; \
+ } \
} while (0)
#else
# define inchar() ((c = getc (s)), (void) ++read_in, c)
-# define conv_error() return ((void) ungetc (c, s), done)
-# define input_error() return (done == 0 ? EOF : done)
-# define memory_error() return ((void) (errno = ENOMEM), EOF)
-# define ARGCHECK(s, format) \
- do \
- { \
- /* Check file argument for consistence. */ \
- if (!__validfp (s) || !s->__mode.__read || format == NULL) \
- { \
- errno = EINVAL; \
- return -1; \
- } \
+# define conv_error() do { \
+ funlockfile (s); \
+ ungetc (c, s); \
+ return done; \
+ } while (0)
+# define input_error() do { \
+ funlockfile (s); \
+ return done ?: EOF; \
+ } while (0)
+# define memory_error() do { \
+ funlockfile (s); \
+ errno = ENOMEM; \
+ return EOF; \
+ } while (0)
+# define ARGCHECK(s, format) \
+ do \
+ { \
+ /* Check file argument for consistence. */ \
+ if (!__validfp (s) || !s->__mode.__read || format == NULL) \
+ { \
+ errno = EINVAL; \
+ return EOF; \
+ } \
} while (0)
#endif
strlen (_NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP))) <= 0)
thousands = (wchar_t) *_NL_CURRENT (LC_NUMERIC, THOUSANDS_SEP);
+ /* Lock the stream. */
+ flockfile (s);
+
c = inchar ();
/* Run through the format string. */
while (isspace (c))
(void) inchar ();
+ /* Unlock stream. */
+ funlockfile (s);
+
return ((void) (c == EOF || ungetc (c, s)), done);
}