2000-02-18 03:39:52 +08:00
|
|
|
/*
|
2007-03-15 Eric Blake <ebb9@byu.net>
* libc/stdio/local.h (cantwrite, FREEUB, FREELB): Make reentrant.
(__smakebuf): Rename...
(__smakebuf_r): to this.
* libc/stdio/fvwrite.h (__swsetup_r): Rename, from __swsetup.
* libc/stdio/makebuf.c (__smakebuf): Detect failed asprint
allocation, then rename...
(__smakebuf_r): ...to this and fix reentrancy.
* libc/stdio/wsetup.c (__swsetup): Detect failed asprintf
allocation, then rename...
(__swsetup_r): ...to this and fix reentrancy.
* libc/stdio/fseek.c (_fseek_r): Fix reentrancy.
* libc/stdio/refill.c (__srefill_r): Likewise.
* libc/stdio/fclose.c (_fclose_r): Likewise.
* libc/stdio/fread.c (_fread_r): Likewise.
* libc/stdio/freopen.c (_freopen_r): Likewise.
* libc/stdio/wbuf.c (__swbuf_r): Likewise.
* libc/stdio64/fseeko64.c (_fseeko64_r): Likewise.
* libc/stdio/fvwrite.c (__sfvwrite_r): Set errno properly on
failed asprintf allocation, and fix reentrancy.
* libc/stdio/snprintf.c (snprintf, _snprintf_r): Report overflow,
as required by POSIX.
* libc/stdio/sniprintf.c (sniprintf, _sniprintf_r): Likewise.
* libc/stdio/vsnprintf.c (vsnprintf, _vsnprintf_r): Likewise.
* libc/stdio/vsniprintf.c (vsniprintf, _vsniprintf_r): Likewise.
2007-03-16 02:40:48 +08:00
|
|
|
* Copyright (c) 1990, 2007 The Regents of the University of California.
|
2000-02-18 03:39:52 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that the above copyright notice and this paragraph are
|
|
|
|
* duplicated in all such forms and that any documentation,
|
|
|
|
* advertising materials, and other materials related to such
|
|
|
|
* distribution and use acknowledge that the software was developed
|
|
|
|
* by the University of California, Berkeley. The name of the
|
|
|
|
* University may not be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
* %W% (UofMD/Berkeley) %G%
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Information local to this implementation of stdio,
|
|
|
|
* in particular, macros and private variables.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <_ansi.h>
|
2004-04-23 Artem B. Bityuckiy <abitytsky@softminecorp.com>
* libc/stdio/asprintf.c libc/stdio/clearerr.c,
libc/stdio/fclose.c libc/stdio/fcloseall.c libc/stdio/fdopen.c,
libc/stdio/feof.c libc/stdio/ferror.c libc/stdio/fflush.c,
libc/stdio/fgetc.c libc/stdio/fgetpos.c libc/stdio/fgets.c,
libc/stdio/fileno.c libc/stdio/findfp.c libc/stdio/fiprintf.c,
libc/stdio/flags.c libc/stdio/fopen.c libc/stdio/fprintf.c,
libc/stdio/fputc.c libc/stdio/fputs.c libc/stdio/fread.c,
libc/stdio/freopen.c libc/stdio/fscanf.c libc/stdio/fseek.c,
libc/stdio/fseeko.c libc/stdio/fsetpos.c libc/stdio/ftell.c,
libc/stdio/ftello.c libc/stdio/fvwrite.c libc/stdio/fwalk.c,
libc/stdio/fwrite.c libc/stdio/getc.c libc/stdio/getc_u.c,
libc/stdio/getchar.c libc/stdio/getchar_u.c,
libc/stdio/getdelim.c libc/stdio/getline.c libc/stdio/gets.c,
libc/stdio/getw.c libc/stdio/iprintf.c libc/stdio/local.h,
libc/stdio/makebuf.c libc/stdio/mktemp.c libc/stdio/perror.c,
libc/stdio/printf.c libc/stdio/putc.c libc/stdio/putc_u.c,
libc/stdio/putchar.c libc/stdio/putchar_u.c libc/stdio/puts.c,
libc/stdio/putw.c libc/stdio/refill.c libc/stdio/remove.c,
libc/stdio/rename.c libc/stdio/rewind.c libc/stdio/rget.c,
libc/stdio/scanf.c libc/stdio/setbuf.c libc/stdio/setbuffer.c,
libc/stdio/setlinebuf.c libc/stdio/setvbuf.c,
libc/stdio/siprintf.c libc/stdio/snprintf.c,
libc/stdio/sprintf.c libc/stdio/sscanf.c libc/stdio/stdio.c,
libc/stdio/tmpfile.c libc/stdio/tmpnam.c libc/stdio/ungetc.c,
libc/stdio/vasprintf.c libc/stdio/vfieeefp.h,
libc/stdio/vfprintf.c libc/stdio/vfscanf.c,
libc/stdio/vprintf.c libc/stdio/vscanf.c,
libc/stdio/vsnprintf.c libc/stdio/vsprintf.c,
libc/stdio/vsscanf.c libc/stdio/wbuf.c,
libc/stdio/wsetup.c: Perform minor formatting changes. Move
copyright notices to top of file, ensure that <_ansi.h> is
included, be consistent with open parentheses, use _DEFUN macro,
include "local.h" where needed, and remove various compiler
warnings.
2004-04-24 04:01:55 +08:00
|
|
|
#include <reent.h>
|
2000-02-18 03:39:52 +08:00
|
|
|
#include <stdarg.h>
|
2004-09-25 00:03:46 +08:00
|
|
|
#include <stdlib.h>
|
2000-02-18 03:39:52 +08:00
|
|
|
#include <unistd.h>
|
Implement funopen, fopencookie.
* libc/include/sys/reent.h (struct __sFILE, struct __sFILE64):
Switch to reentrant callbacks.
* libc/include/stdio.h (funopen): Fix declaration.
(fopencookie): Declare.
* libc/stdio/local.h (__sread, __swrite, __sseek, __sclose)
(__sseek64, __swrite64): Fix prototypes.
[__SCLE]: Pull in setmode declaration.
* libc/stdio/stdio.c (__sread, __swrite, __sseek, __sclose): Fix
reentrancy.
* libc/stdio64/stdio64.c (__sseek64_r, __swrite64_r): Delete.
(__sseek64, __swrite64): Fix reentrancy.
* libc/stdio/fseek.c (_fseek_r): Account for overflow, and fix
reentrancy.
* libc/stdio/ftell.c (_ftell_r): Likewise.
* libc/stdio/flags.c (__sflags): Don't lose __SAPP on "a+".
* libc/stdio/fclose.c (_fclose_r): Fix reentrancy.
* libc/stdio/freopen.c (_freopen_r): Likewise.
* libc/stdio/fvwrite.c (__sfvwrite_r): Likewise.
* libc/stdio/refill.c (__srefill_r): Likewise.
* libc/stdio/siscanf.c (eofread): Likewise.
* libc/stdio/sscanf.c (eofread): Likewise.
* libc/stdio/vsiscanf.c (eofread1): Likewise.
* libc/stdio/vsscanf.c (eofread1): Likewise.
* libc/stdio64/freopen64.c (_freopen64_r): Likewise.
* libc/stdio64/fseeko64.c (_fseeko64_r): Likewise.
* libc/stdio64/ftello64.c (_ftello64_r): Likewise.
* libc/stdio/fflush.c (fflush): Improve reentrancy, although more
could be fixed.
* libc/stdio/fopencookie.c (_fopencookie_r, fopencookie): New file.
* libc/stdio/funopen.c (_funopen_r, funopen): New file.
* libc/stdio/Makefile.am (ELIX_4_SOURCES, CHEWOUT_FILES): Build
new files.
* libc/stdio/Makefile.in: Regenerate.
2007-06-05 02:10:17 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef __SCLE
|
|
|
|
# include <io.h>
|
|
|
|
#endif
|
|
|
|
|
2013-04-25 23:29:19 +08:00
|
|
|
/* The following define determines if the per-reent stdin, stdout and stderr
|
|
|
|
streams are closed during _reclaim_reent(). The stdin, stdout and stderr
|
|
|
|
streams are initialized to use file descriptors 0, 1 and 2 respectively. In
|
|
|
|
case _STDIO_CLOSE_PER_REENT_STD_STREAMS is defined these file descriptors
|
|
|
|
will be closed via close() provided the owner of the reent structure
|
|
|
|
triggerd the on demand reent initilization, see CHECK_INIT(). */
|
2017-06-29 14:17:04 +08:00
|
|
|
#if !defined(__tirtos__)
|
2013-04-25 23:29:19 +08:00
|
|
|
#define _STDIO_CLOSE_PER_REENT_STD_STREAMS
|
|
|
|
#endif
|
|
|
|
|
2012-05-30 16:58:42 +08:00
|
|
|
/* The following macros are supposed to replace calls to _flockfile/_funlockfile
|
|
|
|
and __sfp_lock_acquire/__sfp_lock_release. In case of multi-threaded
|
|
|
|
environments using pthreads, it's not sufficient to lock the stdio functions
|
|
|
|
against concurrent threads accessing the same data, the locking must also be
|
|
|
|
secured against thread cancellation.
|
|
|
|
|
|
|
|
The below macros have to be used in pairs. The _newlib_XXX_start macro
|
|
|
|
starts with a opening curly brace, the _newlib_XXX_end macro ends with a
|
|
|
|
closing curly brace, so the start macro and the end macro mark the code
|
|
|
|
start and end of a critical section. In case the code leaves the critical
|
|
|
|
section before reaching the end of the critical section's code end, use
|
|
|
|
the appropriate _newlib_XXX_exit macro. */
|
|
|
|
|
2013-03-27 00:07:55 +08:00
|
|
|
#if !defined (__SINGLE_THREAD__) && defined (_POSIX_THREADS) \
|
|
|
|
&& !defined (__rtems__)
|
|
|
|
#define _STDIO_WITH_THREAD_CANCELLATION_SUPPORT
|
|
|
|
#endif
|
|
|
|
|
Implement BSD/GNU unlocked stdio extensions.
* libc/include/stdio.h (clearerr_unlocked, feof_unlocked,
ferror_unlocked, fflush_unlocked, fgetc_unlocked, fgets_unlocked,
fileno_unlocked, fputc_unlocked, fputs_unlocked, fread_unlocked,
fwrite_unlocked): Declare.
* libc/include/wchar.h (fgetwc_unlocked, fgetws_unlocked,
fputwc_unlocked, fputws_unlocked, getwc_unlocked, getwchar_unlocked,
putwc_unlocked, putwchar_unlocked): Declare.
* libc/stdio/Makefile.am (ELIX_4_SOURCES): Add clearerr_u.c,
feof_u.c, ferror_u.c, fflush_u.c, fgetc_u.c, fgets_u.c, fgetwc_u.c,
fgetws_u.c, fileno_u.c, fputc_u.c, fputs_u.c, fputwc_u.c, fputws_u.c,
fread_u.c, fwrite_u.c, getwc_u.c, getwchar_u.c, putwc_u.c, putwchar_u.c.
Add necessary dependencies.
* libc/stdio/Makefile.in: Regenerate.
* libc/stdio/clearerr.c: Document unlocked variant.
* libc/stdio/clearerr_u.c: New file.
* libc/stdio/feof.c: Document unlocked variant.
* libc/stdio/feof_u.c: New file.
* libc/stdio/ferror.c: Document unlocked variant.
* libc/stdio/ferror_u.c: New file.
* libc/stdio/fflush.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fflush_u.c: New file.
* libc/stdio/fgetc.c: Document unlocked variants.
* libc/stdio/fgetc_u.c: New file.
* libc/stdio/fgets.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fgets_u.c: New file.
* libc/stdio/fgetwc.c: Document unlocked variants.
(__fgetwc): Make non-static.
* libc/stdio/fgetwc_u.c: New file.
* libc/stdio/fgetws.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fgetws_u.c: New file.
* libc/stdio/fileno.c: Document unlocked variant.
* libc/stdio/fileno_u.c: New file.
* libc/stdio/fputc.c: Document unlocked variants.
* libc/stdio/fputc_u.c: New file.
* libc/stdio/fputs.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fputs_u.c: New file.
* libc/stdio/fputwc.c: Document unlocked variants.
(__fputwc): Make non-static.
* libc/stdio/fputwc_u.c: New file.
* libc/stdio/fputws.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fputws_u.c: New file.
* libc/stdio/fread.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fread_u.c: New file.
* libc/stdio/fwrite.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fwrite_u.c: New file.
* libc/stdio/getwc_u.c: New file.
* libc/stdio/getwchar.c: Document unlocked variants.
* libc/stdio/getwchar_u.c: New file.
* libc/stdio/local.h: Define locking macros as empty ifdef
__IMPL_UNLOCKED__.
(__fgetwc, __fputwc): Declare.
* libc/stdio/putwc_u.c: New file.
* libc/stdio/putwchar.c: Document unlocked variants.
* libc/stdio/putwchar_u.c: New file.
2014-12-18 22:55:21 +08:00
|
|
|
#if defined(__SINGLE_THREAD__) || defined(__IMPL_UNLOCKED__)
|
|
|
|
|
|
|
|
# define _newlib_flockfile_start(_fp)
|
|
|
|
# define _newlib_flockfile_exit(_fp)
|
|
|
|
# define _newlib_flockfile_end(_fp)
|
|
|
|
# define _newlib_sfp_lock_start()
|
|
|
|
# define _newlib_sfp_lock_exit()
|
|
|
|
# define _newlib_sfp_lock_end()
|
|
|
|
|
|
|
|
#elif defined(_STDIO_WITH_THREAD_CANCELLATION_SUPPORT)
|
2012-05-30 16:58:42 +08:00
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
/* Start a stream oriented critical section: */
|
|
|
|
# define _newlib_flockfile_start(_fp) \
|
|
|
|
{ \
|
|
|
|
int __oldfpcancel; \
|
|
|
|
pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldfpcancel); \
|
2014-12-16 02:22:56 +08:00
|
|
|
if (!(_fp->_flags2 & __SNLK)) \
|
|
|
|
_flockfile (_fp)
|
2012-05-30 16:58:42 +08:00
|
|
|
|
|
|
|
/* Exit from a stream oriented critical section prematurely: */
|
|
|
|
# define _newlib_flockfile_exit(_fp) \
|
2014-12-16 02:22:56 +08:00
|
|
|
if (!(_fp->_flags2 & __SNLK)) \
|
|
|
|
_funlockfile (_fp); \
|
2012-05-30 16:58:42 +08:00
|
|
|
pthread_setcancelstate (__oldfpcancel, &__oldfpcancel);
|
|
|
|
|
|
|
|
/* End a stream oriented critical section: */
|
|
|
|
# define _newlib_flockfile_end(_fp) \
|
2014-12-16 02:22:56 +08:00
|
|
|
if (!(_fp->_flags2 & __SNLK)) \
|
|
|
|
_funlockfile (_fp); \
|
2012-05-30 16:58:42 +08:00
|
|
|
pthread_setcancelstate (__oldfpcancel, &__oldfpcancel); \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start a stream list oriented critical section: */
|
|
|
|
# define _newlib_sfp_lock_start() \
|
|
|
|
{ \
|
|
|
|
int __oldsfpcancel; \
|
|
|
|
pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, &__oldsfpcancel); \
|
|
|
|
__sfp_lock_acquire ()
|
|
|
|
|
|
|
|
/* Exit from a stream list oriented critical section prematurely: */
|
|
|
|
# define _newlib_sfp_lock_exit() \
|
|
|
|
__sfp_lock_release (); \
|
|
|
|
pthread_setcancelstate (__oldsfpcancel, &__oldsfpcancel);
|
|
|
|
|
|
|
|
/* End a stream list oriented critical section: */
|
|
|
|
# define _newlib_sfp_lock_end() \
|
|
|
|
__sfp_lock_release (); \
|
|
|
|
pthread_setcancelstate (__oldsfpcancel, &__oldsfpcancel); \
|
|
|
|
}
|
|
|
|
|
Implement BSD/GNU unlocked stdio extensions.
* libc/include/stdio.h (clearerr_unlocked, feof_unlocked,
ferror_unlocked, fflush_unlocked, fgetc_unlocked, fgets_unlocked,
fileno_unlocked, fputc_unlocked, fputs_unlocked, fread_unlocked,
fwrite_unlocked): Declare.
* libc/include/wchar.h (fgetwc_unlocked, fgetws_unlocked,
fputwc_unlocked, fputws_unlocked, getwc_unlocked, getwchar_unlocked,
putwc_unlocked, putwchar_unlocked): Declare.
* libc/stdio/Makefile.am (ELIX_4_SOURCES): Add clearerr_u.c,
feof_u.c, ferror_u.c, fflush_u.c, fgetc_u.c, fgets_u.c, fgetwc_u.c,
fgetws_u.c, fileno_u.c, fputc_u.c, fputs_u.c, fputwc_u.c, fputws_u.c,
fread_u.c, fwrite_u.c, getwc_u.c, getwchar_u.c, putwc_u.c, putwchar_u.c.
Add necessary dependencies.
* libc/stdio/Makefile.in: Regenerate.
* libc/stdio/clearerr.c: Document unlocked variant.
* libc/stdio/clearerr_u.c: New file.
* libc/stdio/feof.c: Document unlocked variant.
* libc/stdio/feof_u.c: New file.
* libc/stdio/ferror.c: Document unlocked variant.
* libc/stdio/ferror_u.c: New file.
* libc/stdio/fflush.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fflush_u.c: New file.
* libc/stdio/fgetc.c: Document unlocked variants.
* libc/stdio/fgetc_u.c: New file.
* libc/stdio/fgets.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fgets_u.c: New file.
* libc/stdio/fgetwc.c: Document unlocked variants.
(__fgetwc): Make non-static.
* libc/stdio/fgetwc_u.c: New file.
* libc/stdio/fgetws.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fgetws_u.c: New file.
* libc/stdio/fileno.c: Document unlocked variant.
* libc/stdio/fileno_u.c: New file.
* libc/stdio/fputc.c: Document unlocked variants.
* libc/stdio/fputc_u.c: New file.
* libc/stdio/fputs.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fputs_u.c: New file.
* libc/stdio/fputwc.c: Document unlocked variants.
(__fputwc): Make non-static.
* libc/stdio/fputwc_u.c: New file.
* libc/stdio/fputws.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fputws_u.c: New file.
* libc/stdio/fread.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fread_u.c: New file.
* libc/stdio/fwrite.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fwrite_u.c: New file.
* libc/stdio/getwc_u.c: New file.
* libc/stdio/getwchar.c: Document unlocked variants.
* libc/stdio/getwchar_u.c: New file.
* libc/stdio/local.h: Define locking macros as empty ifdef
__IMPL_UNLOCKED__.
(__fgetwc, __fputwc): Declare.
* libc/stdio/putwc_u.c: New file.
* libc/stdio/putwchar.c: Document unlocked variants.
* libc/stdio/putwchar_u.c: New file.
2014-12-18 22:55:21 +08:00
|
|
|
#else /* !__SINGLE_THREAD__ && !__IMPL_UNLOCKED__ && !_STDIO_WITH_THREAD_CANCELLATION_SUPPORT */
|
2012-05-30 16:58:42 +08:00
|
|
|
|
|
|
|
# define _newlib_flockfile_start(_fp) \
|
|
|
|
{ \
|
2014-12-16 02:22:56 +08:00
|
|
|
if (!(_fp->_flags2 & __SNLK)) \
|
|
|
|
_flockfile (_fp)
|
2012-05-30 16:58:42 +08:00
|
|
|
|
|
|
|
# define _newlib_flockfile_exit(_fp) \
|
2014-12-16 02:22:56 +08:00
|
|
|
if (!(_fp->_flags2 & __SNLK)) \
|
|
|
|
_funlockfile(_fp); \
|
2012-05-30 16:58:42 +08:00
|
|
|
|
|
|
|
# define _newlib_flockfile_end(_fp) \
|
2014-12-16 02:22:56 +08:00
|
|
|
if (!(_fp->_flags2 & __SNLK)) \
|
|
|
|
_funlockfile(_fp); \
|
2012-05-30 16:58:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# define _newlib_sfp_lock_start() \
|
|
|
|
{ \
|
|
|
|
__sfp_lock_acquire ()
|
|
|
|
|
2012-05-31 15:33:59 +08:00
|
|
|
# define _newlib_sfp_lock_exit() \
|
2012-05-30 16:58:42 +08:00
|
|
|
__sfp_lock_release ();
|
|
|
|
|
|
|
|
# define _newlib_sfp_lock_end() \
|
|
|
|
__sfp_lock_release (); \
|
|
|
|
}
|
|
|
|
|
Implement BSD/GNU unlocked stdio extensions.
* libc/include/stdio.h (clearerr_unlocked, feof_unlocked,
ferror_unlocked, fflush_unlocked, fgetc_unlocked, fgets_unlocked,
fileno_unlocked, fputc_unlocked, fputs_unlocked, fread_unlocked,
fwrite_unlocked): Declare.
* libc/include/wchar.h (fgetwc_unlocked, fgetws_unlocked,
fputwc_unlocked, fputws_unlocked, getwc_unlocked, getwchar_unlocked,
putwc_unlocked, putwchar_unlocked): Declare.
* libc/stdio/Makefile.am (ELIX_4_SOURCES): Add clearerr_u.c,
feof_u.c, ferror_u.c, fflush_u.c, fgetc_u.c, fgets_u.c, fgetwc_u.c,
fgetws_u.c, fileno_u.c, fputc_u.c, fputs_u.c, fputwc_u.c, fputws_u.c,
fread_u.c, fwrite_u.c, getwc_u.c, getwchar_u.c, putwc_u.c, putwchar_u.c.
Add necessary dependencies.
* libc/stdio/Makefile.in: Regenerate.
* libc/stdio/clearerr.c: Document unlocked variant.
* libc/stdio/clearerr_u.c: New file.
* libc/stdio/feof.c: Document unlocked variant.
* libc/stdio/feof_u.c: New file.
* libc/stdio/ferror.c: Document unlocked variant.
* libc/stdio/ferror_u.c: New file.
* libc/stdio/fflush.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fflush_u.c: New file.
* libc/stdio/fgetc.c: Document unlocked variants.
* libc/stdio/fgetc_u.c: New file.
* libc/stdio/fgets.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fgets_u.c: New file.
* libc/stdio/fgetwc.c: Document unlocked variants.
(__fgetwc): Make non-static.
* libc/stdio/fgetwc_u.c: New file.
* libc/stdio/fgetws.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fgetws_u.c: New file.
* libc/stdio/fileno.c: Document unlocked variant.
* libc/stdio/fileno_u.c: New file.
* libc/stdio/fputc.c: Document unlocked variants.
* libc/stdio/fputc_u.c: New file.
* libc/stdio/fputs.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fputs_u.c: New file.
* libc/stdio/fputwc.c: Document unlocked variants.
(__fputwc): Make non-static.
* libc/stdio/fputwc_u.c: New file.
* libc/stdio/fputws.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fputws_u.c: New file.
* libc/stdio/fread.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fread_u.c: New file.
* libc/stdio/fwrite.c: Add __IMPL_UNLOCKED__ overrides.
Document unlocked variants.
* libc/stdio/fwrite_u.c: New file.
* libc/stdio/getwc_u.c: New file.
* libc/stdio/getwchar.c: Document unlocked variants.
* libc/stdio/getwchar_u.c: New file.
* libc/stdio/local.h: Define locking macros as empty ifdef
__IMPL_UNLOCKED__.
(__fgetwc, __fputwc): Declare.
* libc/stdio/putwc_u.c: New file.
* libc/stdio/putwchar.c: Document unlocked variants.
* libc/stdio/putwchar_u.c: New file.
2014-12-18 22:55:21 +08:00
|
|
|
#endif /* __SINGLE_THREAD__ || __IMPL_UNLOCKED__ */
|
2000-02-18 03:39:52 +08:00
|
|
|
|
2017-12-04 13:54:48 +08:00
|
|
|
extern wint_t __fgetwc (struct _reent *, FILE *);
|
|
|
|
extern wint_t __fputwc (struct _reent *, wchar_t, FILE *);
|
|
|
|
extern u_char *__sccl (char *, u_char *fmt);
|
|
|
|
extern int __svfscanf_r (struct _reent *,FILE *, const char *,va_list);
|
|
|
|
extern int __ssvfscanf_r (struct _reent *,FILE *, const char *,va_list);
|
|
|
|
extern int __svfiscanf_r (struct _reent *,FILE *, const char *,va_list);
|
|
|
|
extern int __ssvfiscanf_r (struct _reent *,FILE *, const char *,va_list);
|
|
|
|
extern int __svfwscanf_r (struct _reent *,FILE *, const wchar_t *,va_list);
|
|
|
|
extern int __ssvfwscanf_r (struct _reent *,FILE *, const wchar_t *,va_list);
|
|
|
|
extern int __svfiwscanf_r (struct _reent *,FILE *, const wchar_t *,va_list);
|
|
|
|
extern int __ssvfiwscanf_r (struct _reent *,FILE *, const wchar_t *,va_list);
|
|
|
|
int _svfprintf_r (struct _reent *, FILE *, const char *,
|
2008-04-15 05:14:55 +08:00
|
|
|
va_list)
|
2017-12-04 13:54:48 +08:00
|
|
|
_ATTRIBUTE ((__format__ (__printf__, 3, 0)));
|
|
|
|
int _svfiprintf_r (struct _reent *, FILE *, const char *,
|
2008-04-15 05:14:55 +08:00
|
|
|
va_list)
|
2017-12-04 13:54:48 +08:00
|
|
|
_ATTRIBUTE ((__format__ (__printf__, 3, 0)));
|
|
|
|
int _svfwprintf_r (struct _reent *, FILE *, const wchar_t *,
|
|
|
|
va_list);
|
|
|
|
int _svfiwprintf_r (struct _reent *, FILE *, const wchar_t *,
|
|
|
|
va_list);
|
|
|
|
extern FILE *__sfp (struct _reent *);
|
|
|
|
extern int __sflags (struct _reent *,const char*, int*);
|
|
|
|
extern int __sflush_r (struct _reent *,FILE *);
|
2014-01-17 18:55:32 +08:00
|
|
|
#ifdef _STDIO_BSD_SEMANTICS
|
2017-12-04 13:54:48 +08:00
|
|
|
extern int __sflushw_r (struct _reent *,FILE *);
|
2014-01-17 18:55:32 +08:00
|
|
|
#endif
|
2017-12-04 13:54:48 +08:00
|
|
|
extern int __srefill_r (struct _reent *,FILE *);
|
|
|
|
extern _READ_WRITE_RETURN_TYPE __sread (struct _reent *, void *, char *,
|
|
|
|
_READ_WRITE_BUFSIZE_TYPE);
|
|
|
|
extern _READ_WRITE_RETURN_TYPE __seofread (struct _reent *, void *,
|
2013-10-23 18:04:43 +08:00
|
|
|
char *,
|
2017-12-04 13:54:48 +08:00
|
|
|
_READ_WRITE_BUFSIZE_TYPE);
|
|
|
|
extern _READ_WRITE_RETURN_TYPE __swrite (struct _reent *, void *,
|
2013-10-23 18:04:43 +08:00
|
|
|
const char *,
|
2017-12-04 13:54:48 +08:00
|
|
|
_READ_WRITE_BUFSIZE_TYPE);
|
|
|
|
extern _fpos_t __sseek (struct _reent *, void *, _fpos_t, int);
|
|
|
|
extern int __sclose (struct _reent *, void *);
|
|
|
|
extern int __stextmode (int);
|
|
|
|
extern void __sinit (struct _reent *);
|
|
|
|
extern void _cleanup_r (struct _reent *);
|
|
|
|
extern void __smakebuf_r (struct _reent *, FILE *);
|
|
|
|
extern int __swhatbuf_r (struct _reent *, FILE *, size_t *, int *);
|
|
|
|
extern int _fwalk (struct _reent *, int (*)(FILE *));
|
|
|
|
extern int _fwalk_reent (struct _reent *, int (*)(struct _reent *, FILE *));
|
|
|
|
struct _glue * __sfmoreglue (struct _reent *,int n);
|
|
|
|
extern int __submore (struct _reent *, FILE *);
|
2000-02-18 03:39:52 +08:00
|
|
|
|
2007-05-02 07:03:36 +08:00
|
|
|
#ifdef __LARGE64_FILES
|
2017-12-04 13:54:48 +08:00
|
|
|
extern _fpos64_t __sseek64 (struct _reent *, void *, _fpos64_t, int);
|
|
|
|
extern _READ_WRITE_RETURN_TYPE __swrite64 (struct _reent *, void *,
|
2013-10-23 18:04:43 +08:00
|
|
|
const char *,
|
2017-12-04 13:54:48 +08:00
|
|
|
_READ_WRITE_BUFSIZE_TYPE);
|
2007-05-02 07:03:36 +08:00
|
|
|
#endif
|
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
/* Called by the main entry point fns to ensure stdio has been initialized. */
|
|
|
|
|
2018-02-28 20:31:48 +08:00
|
|
|
#if defined(_REENT_SMALL) && !defined(_REENT_GLOBAL_STDIO_STREAMS)
|
2006-09-27 05:22:19 +08:00
|
|
|
#define CHECK_INIT(ptr, fp) \
|
2013-04-30 05:06:23 +08:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
struct _reent *_check_init_ptr = (ptr); \
|
|
|
|
if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \
|
|
|
|
__sinit (_check_init_ptr); \
|
|
|
|
if ((fp) == (FILE *)&__sf_fake_stdin) \
|
|
|
|
(fp) = _stdin_r(_check_init_ptr); \
|
|
|
|
else if ((fp) == (FILE *)&__sf_fake_stdout) \
|
|
|
|
(fp) = _stdout_r(_check_init_ptr); \
|
|
|
|
else if ((fp) == (FILE *)&__sf_fake_stderr) \
|
|
|
|
(fp) = _stderr_r(_check_init_ptr); \
|
|
|
|
} \
|
2006-09-27 05:22:19 +08:00
|
|
|
while (0)
|
2018-02-28 20:31:48 +08:00
|
|
|
#else /* !_REENT_SMALL || _REENT_GLOBAL_STDIO_STREAMS */
|
2006-09-27 05:22:19 +08:00
|
|
|
#define CHECK_INIT(ptr, fp) \
|
2013-04-30 05:06:23 +08:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
struct _reent *_check_init_ptr = (ptr); \
|
|
|
|
if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \
|
|
|
|
__sinit (_check_init_ptr); \
|
|
|
|
} \
|
2006-09-27 05:22:19 +08:00
|
|
|
while (0)
|
2018-02-28 20:31:48 +08:00
|
|
|
#endif /* !_REENT_SMALL || _REENT_GLOBAL_STDIO_STREAMS */
|
2006-09-27 05:22:19 +08:00
|
|
|
|
|
|
|
#define CHECK_STD_INIT(ptr) \
|
2013-04-30 05:06:23 +08:00
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
struct _reent *_check_init_ptr = (ptr); \
|
|
|
|
if ((_check_init_ptr) && !(_check_init_ptr)->__sdidinit) \
|
|
|
|
__sinit (_check_init_ptr); \
|
|
|
|
} \
|
2000-02-18 03:39:52 +08:00
|
|
|
while (0)
|
|
|
|
|
2011-06-14 11:56:05 +08:00
|
|
|
/* Return true and set errno and stream error flag iff the given FILE
|
|
|
|
cannot be written now. */
|
2000-02-18 03:39:52 +08:00
|
|
|
|
2007-03-15 Eric Blake <ebb9@byu.net>
* libc/stdio/local.h (cantwrite, FREEUB, FREELB): Make reentrant.
(__smakebuf): Rename...
(__smakebuf_r): to this.
* libc/stdio/fvwrite.h (__swsetup_r): Rename, from __swsetup.
* libc/stdio/makebuf.c (__smakebuf): Detect failed asprint
allocation, then rename...
(__smakebuf_r): ...to this and fix reentrancy.
* libc/stdio/wsetup.c (__swsetup): Detect failed asprintf
allocation, then rename...
(__swsetup_r): ...to this and fix reentrancy.
* libc/stdio/fseek.c (_fseek_r): Fix reentrancy.
* libc/stdio/refill.c (__srefill_r): Likewise.
* libc/stdio/fclose.c (_fclose_r): Likewise.
* libc/stdio/fread.c (_fread_r): Likewise.
* libc/stdio/freopen.c (_freopen_r): Likewise.
* libc/stdio/wbuf.c (__swbuf_r): Likewise.
* libc/stdio64/fseeko64.c (_fseeko64_r): Likewise.
* libc/stdio/fvwrite.c (__sfvwrite_r): Set errno properly on
failed asprintf allocation, and fix reentrancy.
* libc/stdio/snprintf.c (snprintf, _snprintf_r): Report overflow,
as required by POSIX.
* libc/stdio/sniprintf.c (sniprintf, _sniprintf_r): Likewise.
* libc/stdio/vsnprintf.c (vsnprintf, _vsnprintf_r): Likewise.
* libc/stdio/vsniprintf.c (vsniprintf, _vsniprintf_r): Likewise.
2007-03-16 02:40:48 +08:00
|
|
|
#define cantwrite(ptr, fp) \
|
2000-02-18 03:39:52 +08:00
|
|
|
((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && \
|
2007-03-15 Eric Blake <ebb9@byu.net>
* libc/stdio/local.h (cantwrite, FREEUB, FREELB): Make reentrant.
(__smakebuf): Rename...
(__smakebuf_r): to this.
* libc/stdio/fvwrite.h (__swsetup_r): Rename, from __swsetup.
* libc/stdio/makebuf.c (__smakebuf): Detect failed asprint
allocation, then rename...
(__smakebuf_r): ...to this and fix reentrancy.
* libc/stdio/wsetup.c (__swsetup): Detect failed asprintf
allocation, then rename...
(__swsetup_r): ...to this and fix reentrancy.
* libc/stdio/fseek.c (_fseek_r): Fix reentrancy.
* libc/stdio/refill.c (__srefill_r): Likewise.
* libc/stdio/fclose.c (_fclose_r): Likewise.
* libc/stdio/fread.c (_fread_r): Likewise.
* libc/stdio/freopen.c (_freopen_r): Likewise.
* libc/stdio/wbuf.c (__swbuf_r): Likewise.
* libc/stdio64/fseeko64.c (_fseeko64_r): Likewise.
* libc/stdio/fvwrite.c (__sfvwrite_r): Set errno properly on
failed asprintf allocation, and fix reentrancy.
* libc/stdio/snprintf.c (snprintf, _snprintf_r): Report overflow,
as required by POSIX.
* libc/stdio/sniprintf.c (sniprintf, _sniprintf_r): Likewise.
* libc/stdio/vsnprintf.c (vsnprintf, _vsnprintf_r): Likewise.
* libc/stdio/vsniprintf.c (vsniprintf, _vsniprintf_r): Likewise.
2007-03-16 02:40:48 +08:00
|
|
|
__swsetup_r(ptr, fp))
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
/* Test whether the given stdio file has an active ungetc buffer;
|
|
|
|
release such a buffer, without restoring ordinary unread data. */
|
|
|
|
|
|
|
|
#define HASUB(fp) ((fp)->_ub._base != NULL)
|
2007-03-15 Eric Blake <ebb9@byu.net>
* libc/stdio/local.h (cantwrite, FREEUB, FREELB): Make reentrant.
(__smakebuf): Rename...
(__smakebuf_r): to this.
* libc/stdio/fvwrite.h (__swsetup_r): Rename, from __swsetup.
* libc/stdio/makebuf.c (__smakebuf): Detect failed asprint
allocation, then rename...
(__smakebuf_r): ...to this and fix reentrancy.
* libc/stdio/wsetup.c (__swsetup): Detect failed asprintf
allocation, then rename...
(__swsetup_r): ...to this and fix reentrancy.
* libc/stdio/fseek.c (_fseek_r): Fix reentrancy.
* libc/stdio/refill.c (__srefill_r): Likewise.
* libc/stdio/fclose.c (_fclose_r): Likewise.
* libc/stdio/fread.c (_fread_r): Likewise.
* libc/stdio/freopen.c (_freopen_r): Likewise.
* libc/stdio/wbuf.c (__swbuf_r): Likewise.
* libc/stdio64/fseeko64.c (_fseeko64_r): Likewise.
* libc/stdio/fvwrite.c (__sfvwrite_r): Set errno properly on
failed asprintf allocation, and fix reentrancy.
* libc/stdio/snprintf.c (snprintf, _snprintf_r): Report overflow,
as required by POSIX.
* libc/stdio/sniprintf.c (sniprintf, _sniprintf_r): Likewise.
* libc/stdio/vsnprintf.c (vsnprintf, _vsnprintf_r): Likewise.
* libc/stdio/vsniprintf.c (vsniprintf, _vsniprintf_r): Likewise.
2007-03-16 02:40:48 +08:00
|
|
|
#define FREEUB(ptr, fp) { \
|
2000-02-18 03:39:52 +08:00
|
|
|
if ((fp)->_ub._base != (fp)->_ubuf) \
|
2007-03-15 Eric Blake <ebb9@byu.net>
* libc/stdio/local.h (cantwrite, FREEUB, FREELB): Make reentrant.
(__smakebuf): Rename...
(__smakebuf_r): to this.
* libc/stdio/fvwrite.h (__swsetup_r): Rename, from __swsetup.
* libc/stdio/makebuf.c (__smakebuf): Detect failed asprint
allocation, then rename...
(__smakebuf_r): ...to this and fix reentrancy.
* libc/stdio/wsetup.c (__swsetup): Detect failed asprintf
allocation, then rename...
(__swsetup_r): ...to this and fix reentrancy.
* libc/stdio/fseek.c (_fseek_r): Fix reentrancy.
* libc/stdio/refill.c (__srefill_r): Likewise.
* libc/stdio/fclose.c (_fclose_r): Likewise.
* libc/stdio/fread.c (_fread_r): Likewise.
* libc/stdio/freopen.c (_freopen_r): Likewise.
* libc/stdio/wbuf.c (__swbuf_r): Likewise.
* libc/stdio64/fseeko64.c (_fseeko64_r): Likewise.
* libc/stdio/fvwrite.c (__sfvwrite_r): Set errno properly on
failed asprintf allocation, and fix reentrancy.
* libc/stdio/snprintf.c (snprintf, _snprintf_r): Report overflow,
as required by POSIX.
* libc/stdio/sniprintf.c (sniprintf, _sniprintf_r): Likewise.
* libc/stdio/vsnprintf.c (vsnprintf, _vsnprintf_r): Likewise.
* libc/stdio/vsniprintf.c (vsniprintf, _vsniprintf_r): Likewise.
2007-03-16 02:40:48 +08:00
|
|
|
_free_r(ptr, (char *)(fp)->_ub._base); \
|
2000-02-18 03:39:52 +08:00
|
|
|
(fp)->_ub._base = NULL; \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test for an fgetline() buffer. */
|
|
|
|
|
|
|
|
#define HASLB(fp) ((fp)->_lb._base != NULL)
|
2007-03-15 Eric Blake <ebb9@byu.net>
* libc/stdio/local.h (cantwrite, FREEUB, FREELB): Make reentrant.
(__smakebuf): Rename...
(__smakebuf_r): to this.
* libc/stdio/fvwrite.h (__swsetup_r): Rename, from __swsetup.
* libc/stdio/makebuf.c (__smakebuf): Detect failed asprint
allocation, then rename...
(__smakebuf_r): ...to this and fix reentrancy.
* libc/stdio/wsetup.c (__swsetup): Detect failed asprintf
allocation, then rename...
(__swsetup_r): ...to this and fix reentrancy.
* libc/stdio/fseek.c (_fseek_r): Fix reentrancy.
* libc/stdio/refill.c (__srefill_r): Likewise.
* libc/stdio/fclose.c (_fclose_r): Likewise.
* libc/stdio/fread.c (_fread_r): Likewise.
* libc/stdio/freopen.c (_freopen_r): Likewise.
* libc/stdio/wbuf.c (__swbuf_r): Likewise.
* libc/stdio64/fseeko64.c (_fseeko64_r): Likewise.
* libc/stdio/fvwrite.c (__sfvwrite_r): Set errno properly on
failed asprintf allocation, and fix reentrancy.
* libc/stdio/snprintf.c (snprintf, _snprintf_r): Report overflow,
as required by POSIX.
* libc/stdio/sniprintf.c (sniprintf, _sniprintf_r): Likewise.
* libc/stdio/vsnprintf.c (vsnprintf, _vsnprintf_r): Likewise.
* libc/stdio/vsniprintf.c (vsniprintf, _vsniprintf_r): Likewise.
2007-03-16 02:40:48 +08:00
|
|
|
#define FREELB(ptr, fp) { _free_r(ptr,(char *)(fp)->_lb._base); \
|
|
|
|
(fp)->_lb._base = NULL; }
|
2000-02-18 03:39:52 +08:00
|
|
|
|
2013-04-12 20:05:31 +08:00
|
|
|
#ifdef _WIDE_ORIENT
|
2008-12-10 Corinna Vinschen <corinna@vinschen.de>
Implement basic wide char stdio functionality, based on FreeBSD.
* libc/include/stdio.h (__SORD): Define.
(__SWID): Define.
* libc/include/wchar.h: Add declarations for new wide char functions.
(getwc): Define as macro.
(getwchar): Ditto.
(putwc): Ditto.
(putwchar): Ditto.
* libc/include/sys/reent.h (struct __sFILE): Add _mbstate member.
(struct __sFILE64): Ditto.
* libc/stdio/Makefile.am (ELIX_4_SOURCES): Add fgetwc.c, fgetws.c,
fputwc.c, fputws.c, fwide.c, getwc.c, getwchar.c, putwc.c, putwchar.c
and ungetwc.c.
(CHEWOUT_FILES): Add fgetwc.def, fgetws.def, fputwc.def, fputws.def,
fwide.def, getwc.def, getwchar.def, putwc.def, putwchar.def and
ungetwc.def.
Add header dependency rules for the new files.
* libc/stdio/Makefile.in: Regenerate.
* libc/stdio/fgetwc.c: New file, implementing fgetwc and _fgetwc_r.
* libc/stdio/fgetws.c: New file, implementing fgetws and _fgetws_r.
* libc/stdio/findfp.c (std): Initialize FILE's _mbstate member.
(__sfmoreglue): Ditto.
* libc/stdio/fputs.c (_fputs_r): Set stream orientation.
* libc/stdio/fputwc.c: New file, implementing fputwc and _fputwc_r.
* libc/stdio/fputws.c: New file, implementing fputws and _fputws_r.
* libc/stdio/fread.c (_fread_r): Set stream orientation.
* libc/stdio/freopen.c (_freopen_r): Reset stream orientation. Reset
_mbstate.
* libc/stdio/fseek.c (_fseek_r): Reset _mbstate.
* libc/stdio/fwide.c: New file, implementing fwide and _fwide_r.
* libc/stdio/fwrite.c (_fwrite_r): Set stream orientation.
* libc/stdio/getwc.c: New file, implementing getwc and _getwc_r.
* libc/stdio/getwchar.c: New file, implementing getwchar and
_getwchar_r.
* libc/stdio/local.h (ORIENT): New macro.
* libc/stdio/puts.c (_puts_r): Set stream orientation.
* libc/stdio/putwc.c: New file, implementing putwc and _putwc_r.
* libc/stdio/putwchar.c: New file, implementing putwchar and
_putwchar_r.
* libc/stdio/refill.c (__srefill_r): Set stream orientation.
* libc/stdio/stdio.tex: Add documentation for new functions.
* libc/stdio/ungetc.c (_ungetc_r): Set stream orientation.
* libc/stdio/ungetwc.c: New file, implementing ungetwc and _ungetwc_r.
* libc/stdio/vfscanf.c (__SVFSCANF_R): Set stream orientation.
* libc/stdio/wbuf.c (__swbuf_r): Ditto.
2008-12-11 07:43:12 +08:00
|
|
|
/*
|
|
|
|
* Set the orientation for a stream. If o > 0, the stream has wide-
|
|
|
|
* orientation. If o < 0, the stream has byte-orientation.
|
|
|
|
*/
|
|
|
|
#define ORIENT(fp,ori) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
if (!((fp)->_flags & __SORD)) \
|
|
|
|
{ \
|
|
|
|
(fp)->_flags |= __SORD; \
|
|
|
|
if (ori > 0) \
|
|
|
|
(fp)->_flags2 |= __SWID; \
|
|
|
|
else \
|
|
|
|
(fp)->_flags2 &= ~__SWID; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
while (0)
|
2013-04-12 20:05:31 +08:00
|
|
|
#else
|
|
|
|
#define ORIENT(fp,ori)
|
|
|
|
#endif
|
2008-12-10 Corinna Vinschen <corinna@vinschen.de>
Implement basic wide char stdio functionality, based on FreeBSD.
* libc/include/stdio.h (__SORD): Define.
(__SWID): Define.
* libc/include/wchar.h: Add declarations for new wide char functions.
(getwc): Define as macro.
(getwchar): Ditto.
(putwc): Ditto.
(putwchar): Ditto.
* libc/include/sys/reent.h (struct __sFILE): Add _mbstate member.
(struct __sFILE64): Ditto.
* libc/stdio/Makefile.am (ELIX_4_SOURCES): Add fgetwc.c, fgetws.c,
fputwc.c, fputws.c, fwide.c, getwc.c, getwchar.c, putwc.c, putwchar.c
and ungetwc.c.
(CHEWOUT_FILES): Add fgetwc.def, fgetws.def, fputwc.def, fputws.def,
fwide.def, getwc.def, getwchar.def, putwc.def, putwchar.def and
ungetwc.def.
Add header dependency rules for the new files.
* libc/stdio/Makefile.in: Regenerate.
* libc/stdio/fgetwc.c: New file, implementing fgetwc and _fgetwc_r.
* libc/stdio/fgetws.c: New file, implementing fgetws and _fgetws_r.
* libc/stdio/findfp.c (std): Initialize FILE's _mbstate member.
(__sfmoreglue): Ditto.
* libc/stdio/fputs.c (_fputs_r): Set stream orientation.
* libc/stdio/fputwc.c: New file, implementing fputwc and _fputwc_r.
* libc/stdio/fputws.c: New file, implementing fputws and _fputws_r.
* libc/stdio/fread.c (_fread_r): Set stream orientation.
* libc/stdio/freopen.c (_freopen_r): Reset stream orientation. Reset
_mbstate.
* libc/stdio/fseek.c (_fseek_r): Reset _mbstate.
* libc/stdio/fwide.c: New file, implementing fwide and _fwide_r.
* libc/stdio/fwrite.c (_fwrite_r): Set stream orientation.
* libc/stdio/getwc.c: New file, implementing getwc and _getwc_r.
* libc/stdio/getwchar.c: New file, implementing getwchar and
_getwchar_r.
* libc/stdio/local.h (ORIENT): New macro.
* libc/stdio/puts.c (_puts_r): Set stream orientation.
* libc/stdio/putwc.c: New file, implementing putwc and _putwc_r.
* libc/stdio/putwchar.c: New file, implementing putwchar and
_putwchar_r.
* libc/stdio/refill.c (__srefill_r): Set stream orientation.
* libc/stdio/stdio.tex: Add documentation for new functions.
* libc/stdio/ungetc.c (_ungetc_r): Set stream orientation.
* libc/stdio/ungetwc.c: New file, implementing ungetwc and _ungetwc_r.
* libc/stdio/vfscanf.c (__SVFSCANF_R): Set stream orientation.
* libc/stdio/wbuf.c (__swbuf_r): Ditto.
2008-12-11 07:43:12 +08:00
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
/* WARNING: _dcvt is defined in the stdlib directory, not here! */
|
|
|
|
|
2017-12-04 13:54:48 +08:00
|
|
|
char *_dcvt (struct _reent *, char *, double, int, int, char, int);
|
|
|
|
char *_sicvt (char *, short, char);
|
|
|
|
char *_icvt (char *, int, char);
|
|
|
|
char *_licvt (char *, long, char);
|
2000-02-18 03:39:52 +08:00
|
|
|
#ifdef __GNUC__
|
2017-12-04 13:54:48 +08:00
|
|
|
char *_llicvt (char *, long long, char);
|
2000-02-18 03:39:52 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CVT_BUF_SIZE 128
|
|
|
|
|
|
|
|
#define NDYNAMIC 4 /* add four more whenever necessary */
|
2004-03-26 06:29:18 +08:00
|
|
|
|
|
|
|
#ifdef __SINGLE_THREAD__
|
|
|
|
#define __sfp_lock_acquire()
|
|
|
|
#define __sfp_lock_release()
|
2005-02-08 09:05:50 +08:00
|
|
|
#define __sinit_lock_acquire()
|
|
|
|
#define __sinit_lock_release()
|
2004-03-26 06:29:18 +08:00
|
|
|
#else
|
2017-12-04 13:54:48 +08:00
|
|
|
void __sfp_lock_acquire (void);
|
|
|
|
void __sfp_lock_release (void);
|
|
|
|
void __sinit_lock_acquire (void);
|
|
|
|
void __sinit_lock_release (void);
|
2004-03-26 06:29:18 +08:00
|
|
|
#endif
|
* libc/include/stdio.h (__VALIST): Guard against multiple definition.
* libc/include/wchar.h: Include stdarg.h.
(__VALIST): Define conditionally.
(fwprintf, swprintf, vfwprintf, vswprintf, vwprintf, wprintf: Declare.
(_fwprintf_r, _swprintf_r, _vfwprintf_r, _vswprintf_r, _vwprintf_r,
_wprintf_r): Declare.
* libc/stdio/Makefile.am: Add new files.
* libc/stdio/Makefile.in: Regenerate.
* libc/stdio/fwprintf.c: New file.
* libc/stdio/local.h (_svfwprintf_r, _svfiwprintf_r): Declare.
(__CH_CLASS, __STATE, __ACTION): Move definition from vfprintf.c here
and move to the __ namespace.
(__chclass, __state_table, __action_table): Declare.
* libc/stdio/stdio.tex: Add new documentation references.
* libc/stdio/swprintf.c: New file.
* libc/stdio/vfprintf.c (__SPRINT): New macro to call the right
__sprint_r function according to compilation unit. Use throughout.
(__ssprint_r): Rename STRING_ONLY variant from __sprint_r.
Make externaly available. Only define if INTEGER_ONLY is defined.
(__sprint_r): Make externaly available. Only define if INTEGER_ONLY
is defined. Handle stream orientation.
(__sbprintf): Copy FILE's _flags2 member as well.
(__chclass, __state_table, __action_table): Prepend __ to name and
make externally available.
* libc/stdio/vfwprintf.c: New file.
* libc/stdio/vswprintf.c: New file.
* libc/stdio/vwprintf.c: New file.
* libc/stdio/wprintf.c: New file.
2009-03-06 17:55:52 +08:00
|
|
|
|
|
|
|
/* Types used in positional argument support in vfprinf/vfwprintf.
|
|
|
|
The implementation is char/wchar_t dependent but the class and state
|
|
|
|
tables are only defined once in vfprintf.c. */
|
2017-03-31 17:00:42 +08:00
|
|
|
typedef enum __packed {
|
* libc/include/stdio.h (__VALIST): Guard against multiple definition.
* libc/include/wchar.h: Include stdarg.h.
(__VALIST): Define conditionally.
(fwprintf, swprintf, vfwprintf, vswprintf, vwprintf, wprintf: Declare.
(_fwprintf_r, _swprintf_r, _vfwprintf_r, _vswprintf_r, _vwprintf_r,
_wprintf_r): Declare.
* libc/stdio/Makefile.am: Add new files.
* libc/stdio/Makefile.in: Regenerate.
* libc/stdio/fwprintf.c: New file.
* libc/stdio/local.h (_svfwprintf_r, _svfiwprintf_r): Declare.
(__CH_CLASS, __STATE, __ACTION): Move definition from vfprintf.c here
and move to the __ namespace.
(__chclass, __state_table, __action_table): Declare.
* libc/stdio/stdio.tex: Add new documentation references.
* libc/stdio/swprintf.c: New file.
* libc/stdio/vfprintf.c (__SPRINT): New macro to call the right
__sprint_r function according to compilation unit. Use throughout.
(__ssprint_r): Rename STRING_ONLY variant from __sprint_r.
Make externaly available. Only define if INTEGER_ONLY is defined.
(__sprint_r): Make externaly available. Only define if INTEGER_ONLY
is defined. Handle stream orientation.
(__sbprintf): Copy FILE's _flags2 member as well.
(__chclass, __state_table, __action_table): Prepend __ to name and
make externally available.
* libc/stdio/vfwprintf.c: New file.
* libc/stdio/vswprintf.c: New file.
* libc/stdio/vwprintf.c: New file.
* libc/stdio/wprintf.c: New file.
2009-03-06 17:55:52 +08:00
|
|
|
ZERO, /* '0' */
|
|
|
|
DIGIT, /* '1-9' */
|
|
|
|
DOLLAR, /* '$' */
|
|
|
|
MODFR, /* spec modifier */
|
|
|
|
SPEC, /* format specifier */
|
|
|
|
DOT, /* '.' */
|
|
|
|
STAR, /* '*' */
|
|
|
|
FLAG, /* format flag */
|
|
|
|
OTHER, /* all other chars */
|
|
|
|
MAX_CH_CLASS /* place-holder */
|
|
|
|
} __CH_CLASS;
|
|
|
|
|
2017-03-31 17:00:42 +08:00
|
|
|
typedef enum __packed {
|
* libc/include/stdio.h (__VALIST): Guard against multiple definition.
* libc/include/wchar.h: Include stdarg.h.
(__VALIST): Define conditionally.
(fwprintf, swprintf, vfwprintf, vswprintf, vwprintf, wprintf: Declare.
(_fwprintf_r, _swprintf_r, _vfwprintf_r, _vswprintf_r, _vwprintf_r,
_wprintf_r): Declare.
* libc/stdio/Makefile.am: Add new files.
* libc/stdio/Makefile.in: Regenerate.
* libc/stdio/fwprintf.c: New file.
* libc/stdio/local.h (_svfwprintf_r, _svfiwprintf_r): Declare.
(__CH_CLASS, __STATE, __ACTION): Move definition from vfprintf.c here
and move to the __ namespace.
(__chclass, __state_table, __action_table): Declare.
* libc/stdio/stdio.tex: Add new documentation references.
* libc/stdio/swprintf.c: New file.
* libc/stdio/vfprintf.c (__SPRINT): New macro to call the right
__sprint_r function according to compilation unit. Use throughout.
(__ssprint_r): Rename STRING_ONLY variant from __sprint_r.
Make externaly available. Only define if INTEGER_ONLY is defined.
(__sprint_r): Make externaly available. Only define if INTEGER_ONLY
is defined. Handle stream orientation.
(__sbprintf): Copy FILE's _flags2 member as well.
(__chclass, __state_table, __action_table): Prepend __ to name and
make externally available.
* libc/stdio/vfwprintf.c: New file.
* libc/stdio/vswprintf.c: New file.
* libc/stdio/vwprintf.c: New file.
* libc/stdio/wprintf.c: New file.
2009-03-06 17:55:52 +08:00
|
|
|
START, /* start */
|
|
|
|
SFLAG, /* seen a flag */
|
|
|
|
WDIG, /* seen digits in width area */
|
|
|
|
WIDTH, /* processed width */
|
|
|
|
SMOD, /* seen spec modifier */
|
|
|
|
SDOT, /* seen dot */
|
|
|
|
VARW, /* have variable width specifier */
|
|
|
|
VARP, /* have variable precision specifier */
|
|
|
|
PREC, /* processed precision */
|
|
|
|
VWDIG, /* have digits in variable width specification */
|
|
|
|
VPDIG, /* have digits in variable precision specification */
|
|
|
|
DONE, /* done */
|
|
|
|
MAX_STATE, /* place-holder */
|
|
|
|
} __STATE;
|
|
|
|
|
2017-03-31 17:00:42 +08:00
|
|
|
typedef enum __packed {
|
* libc/include/stdio.h (__VALIST): Guard against multiple definition.
* libc/include/wchar.h: Include stdarg.h.
(__VALIST): Define conditionally.
(fwprintf, swprintf, vfwprintf, vswprintf, vwprintf, wprintf: Declare.
(_fwprintf_r, _swprintf_r, _vfwprintf_r, _vswprintf_r, _vwprintf_r,
_wprintf_r): Declare.
* libc/stdio/Makefile.am: Add new files.
* libc/stdio/Makefile.in: Regenerate.
* libc/stdio/fwprintf.c: New file.
* libc/stdio/local.h (_svfwprintf_r, _svfiwprintf_r): Declare.
(__CH_CLASS, __STATE, __ACTION): Move definition from vfprintf.c here
and move to the __ namespace.
(__chclass, __state_table, __action_table): Declare.
* libc/stdio/stdio.tex: Add new documentation references.
* libc/stdio/swprintf.c: New file.
* libc/stdio/vfprintf.c (__SPRINT): New macro to call the right
__sprint_r function according to compilation unit. Use throughout.
(__ssprint_r): Rename STRING_ONLY variant from __sprint_r.
Make externaly available. Only define if INTEGER_ONLY is defined.
(__sprint_r): Make externaly available. Only define if INTEGER_ONLY
is defined. Handle stream orientation.
(__sbprintf): Copy FILE's _flags2 member as well.
(__chclass, __state_table, __action_table): Prepend __ to name and
make externally available.
* libc/stdio/vfwprintf.c: New file.
* libc/stdio/vswprintf.c: New file.
* libc/stdio/vwprintf.c: New file.
* libc/stdio/wprintf.c: New file.
2009-03-06 17:55:52 +08:00
|
|
|
NOOP, /* do nothing */
|
|
|
|
NUMBER, /* build a number from digits */
|
|
|
|
SKIPNUM, /* skip over digits */
|
|
|
|
GETMOD, /* get and process format modifier */
|
|
|
|
GETARG, /* get and process argument */
|
|
|
|
GETPW, /* get variable precision or width */
|
|
|
|
GETPWB, /* get variable precision or width and pushback fmt char */
|
|
|
|
GETPOS, /* get positional parameter value */
|
|
|
|
PWPOS, /* get positional parameter value for variable width or precision */
|
|
|
|
} __ACTION;
|
|
|
|
|
2017-12-04 10:25:16 +08:00
|
|
|
extern const __CH_CLASS __chclass[256];
|
|
|
|
extern const __STATE __state_table[MAX_STATE][MAX_CH_CLASS];
|
|
|
|
extern const __ACTION __action_table[MAX_STATE][MAX_CH_CLASS];
|