2006-06-14 Jeff Johnston <jjohnstn@redhat.com>

* libc/include/stdio.h: Add new reentrant I/O prototypes for
        read/write functions.  Change getc/putc macros to have reentrant underlying
        macros/functions.  This includes __sgetc_raw_r, __sgetc_r, and __sputc_r.
        * libc/stdio/fgetc.c: Fix and/or add reentrant version to call
        new reentrant I/O functions/macros for reading/writing.
        * libc/stdio/fgets.c: Ditto.
        * libc/stdio/fputc.c: Ditto.
        * libc/stdio/fputs.c: Ditto.
        * libc/stdio/fread.c: Ditto.
        * libc/stdio/fseek.c: Ditto.
        * libc/stdio64/fseeko64.c: Ditto.
        * libc/stdio/fwrite.c: Ditto.
        * libc/stdio/getc.c: Ditto.
        * libc/stdio/getc_u.c: Ditto.
        * libc/stdio/getchar.c: Ditto.
        * libc/stdio/getchar_u.c: Ditto.
        * libc/stdio/putc.c: Ditto.
        * libc/stdio/putc_u.c: Ditto.
        * libc/stdio/putchar.c: Ditto.
        * libc/stdio/puts.c: Ditto.
        * libc/stdio/vfprintf.c: Ditto.
        * libc/stdio/vfscanf.c: Ditto.
        * libc/stdio/fvwrite.c: Change __sfvwrite into reentrant __sfvwrite_r.
        Change all previous callers of __sfvwrite.  Set errno to EBADF and
        set error flag on if attempt is made to write to file that does not
        allow writing.
        * libc/stdio/fvwrite.h: Fix new reentrant prototypes.
        * libc/stdio/local.h: Ditto.
        * libc/stdio/refill.c: Turn __srefill into reentrant __srefill_r.
        Set errno to EBADF and the error flag on if attempt is made to
        read unreadable file.  Change all previous callers of __srefill.
        * libc/stdio/rget.c
        * libc/stdio/wbuf.c: Turn __swbuf into reentrant __swbuf_r.  Change
        all previous callers of __swbuf.
        * libc/sys/linux/machine/i386/huge_val.h: Ifdef out file contents since
        huge value macros are already defined correctly for i386 by <math.h>.
This commit is contained in:
Jeff Johnston 2006-06-14 20:49:11 +00:00
parent 1b9cba59c3
commit 4dc0c0c4e5
27 changed files with 473 additions and 98 deletions

View File

@ -1,3 +1,42 @@
2006-06-14 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/stdio.h: Add new reentrant I/O prototypes for
read/write functions. Change getc/putc macros to have reentrant underlying
macros/functions. This includes __sgetc_raw_r, __sgetc_r, and __sputc_r.
* libc/stdio/fgetc.c: Fix and/or add reentrant version to call
new reentrant I/O functions/macros for reading/writing.
* libc/stdio/fgets.c: Ditto.
* libc/stdio/fputc.c: Ditto.
* libc/stdio/fputs.c: Ditto.
* libc/stdio/fread.c: Ditto.
* libc/stdio/fseek.c: Ditto.
* libc/stdio64/fseeko64.c: Ditto.
* libc/stdio/fwrite.c: Ditto.
* libc/stdio/getc.c: Ditto.
* libc/stdio/getc_u.c: Ditto.
* libc/stdio/getchar.c: Ditto.
* libc/stdio/getchar_u.c: Ditto.
* libc/stdio/putc.c: Ditto.
* libc/stdio/putc_u.c: Ditto.
* libc/stdio/putchar.c: Ditto.
* libc/stdio/puts.c: Ditto.
* libc/stdio/vfprintf.c: Ditto.
* libc/stdio/vfscanf.c: Ditto.
* libc/stdio/fvwrite.c: Change __sfvwrite into reentrant __sfvwrite_r.
Change all previous callers of __sfvwrite. Set errno to EBADF and
set error flag on if attempt is made to write to file that does not
allow writing.
* libc/stdio/fvwrite.h: Fix new reentrant prototypes.
* libc/stdio/local.h: Ditto.
* libc/stdio/refill.c: Turn __srefill into reentrant __srefill_r.
Set errno to EBADF and the error flag on if attempt is made to
read unreadable file. Change all previous callers of __srefill.
* libc/stdio/rget.c
* libc/stdio/wbuf.c: Turn __swbuf into reentrant __swbuf_r. Change
all previous callers of __swbuf.
* libc/sys/linux/machine/i386/huge_val.h: Ifdef out file contents since
huge value macros are already defined correctly for i386 by <math.h>.
2006-06-13 Sandra Loosemore <sandra@codesourcery.com> 2006-06-13 Sandra Loosemore <sandra@codesourcery.com>
* /libc/sys/arm/syscalls.c (_unlink, isatty, _system, _rename): * /libc/sys/arm/syscalls.c (_unlink, isatty, _system, _rename):

View File

@ -293,11 +293,19 @@ int _EXFUN(_fcloseall_r, (struct _reent *));
FILE * _EXFUN(_fdopen_r, (struct _reent *, int, const char *)); FILE * _EXFUN(_fdopen_r, (struct _reent *, int, const char *));
FILE * _EXFUN(_fopen_r, (struct _reent *, const char *, const char *)); FILE * _EXFUN(_fopen_r, (struct _reent *, const char *, const char *));
int _EXFUN(_fclose_r, (struct _reent *, FILE *)); int _EXFUN(_fclose_r, (struct _reent *, FILE *));
char * _EXFUN(_fgets_r, (struct _reent *, char *, int, FILE *));
int _EXFUN(_fiscanf_r, (struct _reent *, FILE *, const char *, ...)); int _EXFUN(_fiscanf_r, (struct _reent *, FILE *, const char *, ...));
int _EXFUN(_fputc_r, (struct _reent *, int, FILE *));
int _EXFUN(_fputs_r, (struct _reent *, const char *, FILE *));
size_t _EXFUN(_fread_r, (struct _reent *, _PTR, size_t _size, size_t _n, FILE *));
int _EXFUN(_fscanf_r, (struct _reent *, FILE *, const char *, ...)); int _EXFUN(_fscanf_r, (struct _reent *, FILE *, const char *, ...));
int _EXFUN(_fseek_r, (struct _reent *, FILE *, long, int)); int _EXFUN(_fseek_r, (struct _reent *, FILE *, long, int));
long _EXFUN(_ftell_r, (struct _reent *, FILE *)); long _EXFUN(_ftell_r, (struct _reent *, FILE *));
size_t _EXFUN(_fwrite_r, (struct _reent *, const _PTR , size_t _size, size_t _n, FILE *));
int _EXFUN(_getc_r, (struct _reent *, FILE *));
int _EXFUN(_getc_unlocked_r, (struct _reent *, FILE *));
int _EXFUN(_getchar_r, (struct _reent *)); int _EXFUN(_getchar_r, (struct _reent *));
int _EXFUN(_getchar_unlocked_r, (struct _reent *));
char * _EXFUN(_gets_r, (struct _reent *, char *)); char * _EXFUN(_gets_r, (struct _reent *, char *));
int _EXFUN(_iprintf_r, (struct _reent *, const char *, ...)); int _EXFUN(_iprintf_r, (struct _reent *, const char *, ...));
int _EXFUN(_iscanf_r, (struct _reent *, const char *, ...)); int _EXFUN(_iscanf_r, (struct _reent *, const char *, ...));
@ -305,6 +313,9 @@ int _EXFUN(_mkstemp_r, (struct _reent *, char *));
char * _EXFUN(_mktemp_r, (struct _reent *, char *)); char * _EXFUN(_mktemp_r, (struct _reent *, char *));
void _EXFUN(_perror_r, (struct _reent *, const char *)); void _EXFUN(_perror_r, (struct _reent *, const char *));
int _EXFUN(_printf_r, (struct _reent *, const char *, ...)); int _EXFUN(_printf_r, (struct _reent *, const char *, ...));
int _EXFUN(_putc_r, (struct _reent *, int, FILE *));
int _EXFUN(_putc_unlocked_r, (struct _reent *, int, FILE *));
int _EXFUN(_putchar_unlocked_r, (struct _reent *, int));
int _EXFUN(_putchar_r, (struct _reent *, int)); int _EXFUN(_putchar_r, (struct _reent *, int));
int _EXFUN(_puts_r, (struct _reent *, const char *)); int _EXFUN(_puts_r, (struct _reent *, const char *));
int _EXFUN(_remove_r, (struct _reent *, const char *)); int _EXFUN(_remove_r, (struct _reent *, const char *));
@ -366,8 +377,8 @@ FILE * _EXFUN(_tmpfile64_r, (struct _reent *));
* Routines internal to the implementation. * Routines internal to the implementation.
*/ */
int _EXFUN(__srget, (FILE *)); int _EXFUN(__srget_r, (struct _reent *, FILE *));
int _EXFUN(__swbuf, (int, FILE *)); int _EXFUN(__swbuf_r, (struct _reent *, int, FILE *));
/* /*
* Stdio function-access interface. * Stdio function-access interface.
@ -388,15 +399,15 @@ FILE *_EXFUN(funopen,(const _PTR _cookie,
* The __sfoo macros are here so that we can * The __sfoo macros are here so that we can
* define function versions in the C library. * define function versions in the C library.
*/ */
#define __sgetc_raw(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) #define __sgetc_raw_r(__ptr, __f) (--(__f)->_r < 0 ? __srget_r(__ptr, __f) : (int)(*(__f)->_p++))
#ifdef __SCLE #ifdef __SCLE
static __inline__ int __sgetc(FILE *__p) static __inline__ int __sgetc_r(struct _REENT *__ptr, FILE *__p)
{ {
int __c = __sgetc_raw(__p); int __c = __sgetc_raw_r(__ptr, __p);
if ((__p->_flags & __SCLE) && (__c == '\r')) if ((__p->_flags & __SCLE) && (__c == '\r'))
{ {
int __c2 = __sgetc_raw(__p); int __c2 = __sgetc_raw_r(__ptr, __p);
if (__c2 == '\n') if (__c2 == '\n')
__c = __c2; __c = __c2;
else else
@ -405,37 +416,37 @@ static __inline__ int __sgetc(FILE *__p)
return __c; return __c;
} }
#else #else
#define __sgetc(p) __sgetc_raw(p) #define __sgetc_r(__ptr, __p) __sgetc_raw_r(__ptr, __p)
#endif #endif
#ifdef _never /* __GNUC__ */ #ifdef _never /* __GNUC__ */
/* If this inline is actually used, then systems using coff debugging /* If this inline is actually used, then systems using coff debugging
info get hopelessly confused. 21sept93 rich@cygnus.com. */ info get hopelessly confused. 21sept93 rich@cygnus.com. */
static __inline int __sputc(int _c, FILE *_p) { static __inline int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) {
if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
return (*_p->_p++ = _c); return (*_p->_p++ = _c);
else else
return (__swbuf(_c, _p)); return (__swbuf_r(_ptr, _c, _p));
} }
#else #else
/* /*
* This has been tuned to generate reasonable code on the vax using pcc * This has been tuned to generate reasonable code on the vax using pcc
*/ */
#define __sputc_raw(c, p) \ #define __sputc_raw_r(__ptr, __c, __p) \
(--(p)->_w < 0 ? \ (--(__p)->_w < 0 ? \
(p)->_w >= (p)->_lbfsize ? \ (__p)->_w >= (__p)->_lbfsize ? \
(*(p)->_p = (c)), *(p)->_p != '\n' ? \ (*(__p)->_p = (__c)), *(__p)->_p != '\n' ? \
(int)*(p)->_p++ : \ (int)*(__p)->_p++ : \
__swbuf('\n', p) : \ __swbuf_r(__ptr, '\n', __p) : \
__swbuf((int)(c), p) : \ __swbuf_r(__ptr, (int)(__c), __p) : \
(*(p)->_p = (c), (int)*(p)->_p++)) (*(__p)->_p = (__c), (int)*(__p)->_p++))
#ifdef __SCLE #ifdef __SCLE
#define __sputc(c, p) \ #define __sputc_r(__ptr, __c, __p) \
((((p)->_flags & __SCLE) && ((c) == '\n')) \ ((((__p)->_flags & __SCLE) && ((__c) == '\n')) \
? __sputc_raw('\r', (p)) : 0 , \ ? __sputc_raw_r(__ptr, '\r', (__p)) : 0 , \
__sputc_raw((c), (p))) __sputc_raw_r((__ptr), (__c), (__p)))
#else #else
#define __sputc(c, p) __sputc_raw(c, p) #define __sputc_r(__ptr, __c, __p) __sputc_raw_r(__ptr, __c, __p)
#endif #endif
#endif #endif
@ -454,8 +465,8 @@ static __inline int __sputc(int _c, FILE *_p) {
#ifndef __CYGWIN__ #ifndef __CYGWIN__
#ifndef lint #ifndef lint
#define getc(fp) __sgetc(fp) #define getc(fp) __sgetc_r(_REENT, fp)
#define putc(x, fp) __sputc(x, fp) #define putc(x, fp) __sputc_r(_REENT, x, fp)
#endif /* lint */ #endif /* lint */
#endif /* __CYGWIN__ */ #endif /* __CYGWIN__ */
@ -465,7 +476,7 @@ static __inline int __sputc(int _c, FILE *_p) {
#ifndef __STRICT_ANSI__ #ifndef __STRICT_ANSI__
/* fast always-buffered version, true iff error */ /* fast always-buffered version, true iff error */
#define fast_putc(x,p) (--(p)->_w < 0 ? \ #define fast_putc(x,p) (--(p)->_w < 0 ? \
__swbuf((int)(x), p) == EOF : (*(p)->_p = (x), (p)->_p++, 0)) __swbuf_r(_REENT, (int)(x), p) == EOF : (*(p)->_p = (x), (p)->_p++, 0))
#define L_cuserid 9 /* posix says it goes in stdio.h :( */ #define L_cuserid 9 /* posix says it goes in stdio.h :( */
#ifdef __CYGWIN__ #ifdef __CYGWIN__

View File

@ -21,16 +21,26 @@ FUNCTION
INDEX INDEX
fgetc fgetc
INDEX
_fgetc_r
ANSI_SYNOPSIS ANSI_SYNOPSIS
#include <stdio.h> #include <stdio.h>
int fgetc(FILE *<[fp]>); int fgetc(FILE *<[fp]>);
#include <stdio.h>
int _fgetc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
TRAD_SYNOPSIS TRAD_SYNOPSIS
#include <stdio.h> #include <stdio.h>
int fgetc(<[fp]>) int fgetc(<[fp]>)
FILE *<[fp]>; FILE *<[fp]>;
#include <stdio.h>
int _fgetc_r(<[ptr]>, <[fp]>)
struct _reent *<[ptr]>;
FILE *<[fp]>;
DESCRIPTION DESCRIPTION
Use <<fgetc>> to get the next single character from the file or stream Use <<fgetc>> to get the next single character from the file or stream
identified by <[fp]>. As a side effect, <<fgetc>> advances the file's identified by <[fp]>. As a side effect, <<fgetc>> advances the file's
@ -38,6 +48,10 @@ current position indicator.
For a macro version of this function, see <<getc>>. For a macro version of this function, see <<getc>>.
The function <<_fgetc_r>> is simply a reentrant version of
<<fgetc>> that is passed the additional reentrant structure
pointer argument: <[ptr]>.
RETURNS RETURNS
The next character (read as an <<unsigned char>>, and cast to The next character (read as an <<unsigned char>>, and cast to
<<int>>), unless there is no more data, or the host system reports a <<int>>), unless there is no more data, or the host system reports a
@ -58,13 +72,35 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
#include "local.h" #include "local.h"
int int
_DEFUN(fgetc, (fp), _DEFUN(_fgetc_r, (ptr, fp),
struct _reent * ptr _AND
FILE * fp) FILE * fp)
{ {
int result; int result;
CHECK_INIT(_REENT); CHECK_INIT(ptr);
_flockfile (fp); _flockfile (fp);
result = __sgetc (fp); result = __sgetc_r (ptr, fp);
_funlockfile (fp); _funlockfile (fp);
return result; return result;
} }
#ifndef _REENT_ONLY
int
_DEFUN(fgetc, (fp),
FILE * fp)
{
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
int result;
CHECK_INIT(_REENT);
_flockfile (fp);
result = __sgetc_r (_REENT, fp);
_funlockfile (fp);
return result;
#else
return _fgetc_r (_REENT, fp);
#endif
}
#endif /* !_REENT_ONLY */

View File

@ -21,11 +21,16 @@ FUNCTION
INDEX INDEX
fgets fgets
INDEX
_fgets_r
ANSI_SYNOPSIS ANSI_SYNOPSIS
#include <stdio.h> #include <stdio.h>
char *fgets(char *<[buf]>, int <[n]>, FILE *<[fp]>); char *fgets(char *<[buf]>, int <[n]>, FILE *<[fp]>);
#include <stdio.h>
char *_fgets_r(struct _reent *<[ptr]>, char *<[buf]>, int <[n]>, FILE *<[fp]>);
TRAD_SYNOPSIS TRAD_SYNOPSIS
#include <stdio.h> #include <stdio.h>
char *fgets(<[buf]>,<[n]>,<[fp]>) char *fgets(<[buf]>,<[n]>,<[fp]>)
@ -33,11 +38,21 @@ TRAD_SYNOPSIS
int <[n]>; int <[n]>;
FILE *<[fp]>; FILE *<[fp]>;
#include <stdio.h>
char *_fgets_r(<[ptr]>, <[buf]>,<[n]>,<[fp]>)
struct _reent *<[ptr]>;
char *<[buf]>;
int <[n]>;
FILE *<[fp]>;
DESCRIPTION DESCRIPTION
Reads at most <[n-1]> characters from <[fp]> until a newline Reads at most <[n-1]> characters from <[fp]> until a newline
is found. The characters including to the newline are stored is found. The characters including to the newline are stored
in <[buf]>. The buffer is terminated with a 0. in <[buf]>. The buffer is terminated with a 0.
The <<_fgets_r>> function is simply the reentrant version of
<<fgets>> and is passed an additional reentrancy structure
pointer: <[ptr]>.
RETURNS RETURNS
<<fgets>> returns the buffer passed to it, with the data <<fgets>> returns the buffer passed to it, with the data
@ -66,7 +81,8 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
*/ */
char * char *
_DEFUN(fgets, (buf, n, fp), _DEFUN(_fgets_r, (ptr, buf, n, fp),
struct _reent * ptr _AND
char *buf _AND char *buf _AND
int n _AND int n _AND
FILE * fp) FILE * fp)
@ -80,7 +96,7 @@ _DEFUN(fgets, (buf, n, fp),
s = buf; s = buf;
CHECK_INIT(_REENT); CHECK_INIT(ptr);
_flockfile (fp); _flockfile (fp);
#ifdef __SCLE #ifdef __SCLE
@ -88,7 +104,7 @@ _DEFUN(fgets, (buf, n, fp),
{ {
int c; int c;
/* Sorry, have to do it the slow way */ /* Sorry, have to do it the slow way */
while (--n > 0 && (c = __sgetc (fp)) != EOF) while (--n > 0 && (c = __sgetc_r (ptr, fp)) != EOF)
{ {
*s++ = c; *s++ = c;
if (c == '\n') if (c == '\n')
@ -113,7 +129,7 @@ _DEFUN(fgets, (buf, n, fp),
*/ */
if ((len = fp->_r) <= 0) if ((len = fp->_r) <= 0)
{ {
if (__srefill (fp)) if (__srefill_r (ptr, fp))
{ {
/* EOF: stop with partial or no line */ /* EOF: stop with partial or no line */
if (s == buf) if (s == buf)
@ -156,3 +172,16 @@ _DEFUN(fgets, (buf, n, fp),
_funlockfile (fp); _funlockfile (fp);
return buf; return buf;
} }
#ifndef _REENT_ONLY
char *
_DEFUN(fgets, (buf, n, fp),
char *buf _AND
int n _AND
FILE * fp)
{
return _fgets_r (_REENT, buf, n, fp);
}
#endif /* !_REENT_ONLY */

View File

@ -21,17 +21,28 @@ FUNCTION
INDEX INDEX
fputc fputc
INDEX
_fputc_r
ANSI_SYNOPSIS ANSI_SYNOPSIS
#include <stdio.h> #include <stdio.h>
int fputc(int <[ch]>, FILE *<[fp]>); int fputc(int <[ch]>, FILE *<[fp]>);
#include <stdio.h>
int _fputc_r(struct _rent *<[ptr]>, int <[ch]>, FILE *<[fp]>);
TRAD_SYNOPSIS TRAD_SYNOPSIS
#include <stdio.h> #include <stdio.h>
int fputc(<[ch]>, <[fp]>) int fputc(<[ch]>, <[fp]>)
int <[ch]>; int <[ch]>;
FILE *<[fp]>; FILE *<[fp]>;
#include <stdio.h>
int _fputc_r(<[ptr]>, <[ch]>, <[fp]>)
struct _reent *<[ptr]>;
int <[ch]>;
FILE *<[fp]>;
DESCRIPTION DESCRIPTION
<<fputc>> converts the argument <[ch]> from an <<int>> to an <<fputc>> converts the argument <[ch]> from an <<int>> to an
<<unsigned char>>, then writes it to the file or stream identified by <<unsigned char>>, then writes it to the file or stream identified by
@ -45,6 +56,9 @@ oadvances by one.
For a macro version of this function, see <<putc>>. For a macro version of this function, see <<putc>>.
The <<_fputc_r>> function is simply a reentrant version of <<fputc>>
that takes an additional reentrant structure argument: <[ptr]>.
RETURNS RETURNS
If successful, <<fputc>> returns its argument <[ch]>. If an error If successful, <<fputc>> returns its argument <[ch]>. If an error
intervenes, the result is <<EOF>>. You can use `<<ferror(<[fp]>)>>' to intervenes, the result is <<EOF>>. You can use `<<ferror(<[fp]>)>>' to
@ -62,14 +76,34 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
#include "local.h" #include "local.h"
int int
_DEFUN(fputc, (ch, file), _DEFUN(_fputc_r, (ptr, ch, file),
struct _reent *ptr _AND
int ch _AND int ch _AND
FILE * file) FILE * file)
{ {
int result; int result;
CHECK_INIT(_REENT); CHECK_INIT(ptr);
_flockfile (file); _flockfile (file);
result = putc (ch, file); result = _putc_r (ptr, ch, file);
_funlockfile (file); _funlockfile (file);
return result; return result;
} }
#ifndef _REENT_ONLY
int
_DEFUN(fputc, (ch, file),
int ch _AND
FILE * file)
{
#if !defined(__OPTIMIZE_SIZE__) && !defined(PREFER_SIZE_OVER_SPEED)
int result;
CHECK_INIT(_REENT);
_flockfile (file);
result = _putc_r (_REENT, ch, file);
_funlockfile (file);
return result;
#else
return _fputc_r (_REENT, ch, file);
#endif
}
#endif /* !_REENT_ONLY */

View File

@ -21,21 +21,35 @@ FUNCTION
INDEX INDEX
fputs fputs
INDEX
_fputs_r
ANSI_SYNOPSIS ANSI_SYNOPSIS
#include <stdio.h> #include <stdio.h>
int fputs(const char *<[s]>, FILE *<[fp]>); int fputs(const char *<[s]>, FILE *<[fp]>);
#include <stdio.h>
int _fputs_r(struct _reent *<[ptr]>, const char *<[s]>, FILE *<[fp]>);
TRAD_SYNOPSIS TRAD_SYNOPSIS
#include <stdio.h> #include <stdio.h>
int fputs(<[s]>, <[fp]>) int fputs(<[s]>, <[fp]>)
char *<[s]>; char *<[s]>;
FILE *<[fp]>; FILE *<[fp]>;
#include <stdio.h>
int _fputs_r(<[ptr]>, <[s]>, <[fp]>)
struct _reent *<[ptr]>;
char *<[s]>;
FILE *<[fp]>;
DESCRIPTION DESCRIPTION
<<fputs>> writes the string at <[s]> (but without the trailing null) <<fputs>> writes the string at <[s]> (but without the trailing null)
to the file or stream identified by <[fp]>. to the file or stream identified by <[fp]>.
<<_fputs_r>> is simply the reentrant version of <<fputs>> that takes
an additional reentrant struct pointer argument: <[ptr]>.
RETURNS RETURNS
If successful, the result is <<0>>; otherwise, the result is <<EOF>>. If successful, the result is <<0>>; otherwise, the result is <<EOF>>.
@ -58,7 +72,8 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
*/ */
int int
_DEFUN(fputs, (s, fp), _DEFUN(_fputs_r, (ptr, s, fp),
struct _reent * ptr _AND
char _CONST * s _AND char _CONST * s _AND
FILE * fp) FILE * fp)
{ {
@ -71,10 +86,20 @@ _DEFUN(fputs, (s, fp),
uio.uio_iov = &iov; uio.uio_iov = &iov;
uio.uio_iovcnt = 1; uio.uio_iovcnt = 1;
CHECK_INIT(_REENT); CHECK_INIT(ptr);
_flockfile (fp); _flockfile (fp);
result = __sfvwrite (fp, &uio); result = __sfvwrite_r (ptr, fp, &uio);
_funlockfile (fp); _funlockfile (fp);
return result; return result;
} }
#ifndef _REENT_ONLY
int
_DEFUN(fputs, (s, fp),
char _CONST * s _AND
FILE * fp)
{
return _fputs_r (_REENT, s, fp);
}
#endif /* !_REENT_ONLY */

View File

@ -21,12 +21,19 @@ FUNCTION
INDEX INDEX
fread fread
INDEX
_fread_r
ANSI_SYNOPSIS ANSI_SYNOPSIS
#include <stdio.h> #include <stdio.h>
size_t fread(void *<[buf]>, size_t <[size]>, size_t <[count]>, size_t fread(void *<[buf]>, size_t <[size]>, size_t <[count]>,
FILE *<[fp]>); FILE *<[fp]>);
#include <stdio.h>
size_t _fread_r(struct _reent *<[ptr]>, void *<[buf]>,
size_t <[size]>, size_t <[count]>,
FILE *<[fp]>);
TRAD_SYNOPSIS TRAD_SYNOPSIS
#include <stdio.h> #include <stdio.h>
size_t fread(<[buf]>, <[size]>, <[count]>, <[fp]>) size_t fread(<[buf]>, <[size]>, <[count]>, <[fp]>)
@ -35,6 +42,14 @@ TRAD_SYNOPSIS
size_t <[count]>; size_t <[count]>;
FILE *<[fp]>; FILE *<[fp]>;
#include <stdio.h>
size_t _fread_r(<[ptr]>, <[buf]>, <[size]>, <[count]>, <[fp]>)
struct _reent *<[ptr]>;
char *<[buf]>;
size_t <[size]>;
size_t <[count]>;
FILE *<[fp]>;
DESCRIPTION DESCRIPTION
<<fread>> attempts to copy, from the file or stream identified by <<fread>> attempts to copy, from the file or stream identified by
<[fp]>, <[count]> elements (each of size <[size]>) into memory, <[fp]>, <[count]> elements (each of size <[size]>) into memory,
@ -44,6 +59,9 @@ starting at <[buf]>. <<fread>> may copy fewer elements than
<<fread>> also advances the file position indicator (if any) for <<fread>> also advances the file position indicator (if any) for
<[fp]> by the number of @emph{characters} actually read. <[fp]> by the number of @emph{characters} actually read.
<<_fread_r>> is simply the reentrant version of <<fread>> that
takes an additional reentrant structure pointer argument: <[ptr]>.
RETURNS RETURNS
The result of <<fread>> is the number of elements it succeeded in The result of <<fread>> is the number of elements it succeeded in
reading. reading.
@ -63,7 +81,8 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
#ifdef __SCLE #ifdef __SCLE
static size_t static size_t
_DEFUN(crlf, (fp, buf, count, eof), _DEFUN(crlf_r, (ptr, fp, buf, count, eof),
struct _reent * ptr _AND
FILE * fp _AND FILE * fp _AND
char * buf _AND char * buf _AND
size_t count _AND size_t count _AND
@ -86,7 +105,7 @@ _DEFUN(crlf, (fp, buf, count, eof),
{ {
if (*s == '\r') if (*s == '\r')
{ {
int c = __sgetc_raw (fp); int c = __sgetc_raw_r (ptr, fp);
if (c == '\n') if (c == '\n')
*s = '\n'; *s = '\n';
else else
@ -98,7 +117,7 @@ _DEFUN(crlf, (fp, buf, count, eof),
while (d < e) while (d < e)
{ {
r = getc (fp); r = _getc_r (ptr, fp);
if (r == EOF) if (r == EOF)
return count - (e-d); return count - (e-d);
*d++ = r; *d++ = r;
@ -111,7 +130,8 @@ _DEFUN(crlf, (fp, buf, count, eof),
#endif #endif
size_t size_t
_DEFUN(fread, (buf, size, count, fp), _DEFUN(_fread_r, (ptr, buf, size, count, fp),
struct _reent * ptr _AND
_PTR buf _AND _PTR buf _AND
size_t size _AND size_t size _AND
size_t count _AND size_t count _AND
@ -125,7 +145,7 @@ _DEFUN(fread, (buf, size, count, fp),
if ((resid = count * size) == 0) if ((resid = count * size) == 0)
return 0; return 0;
CHECK_INIT(_REENT); CHECK_INIT(ptr);
_flockfile (fp); _flockfile (fp);
if (fp->_r < 0) if (fp->_r < 0)
@ -162,7 +182,7 @@ _DEFUN(fread, (buf, size, count, fp),
fp->_bf._base = p; fp->_bf._base = p;
fp->_bf._size = resid; fp->_bf._size = resid;
fp->_p = p; fp->_p = p;
rc = __srefill (fp); rc = __srefill_r (ptr, fp);
/* restore fp buffering back to original state */ /* restore fp buffering back to original state */
fp->_bf._base = old_base; fp->_bf._base = old_base;
fp->_bf._size = old_size; fp->_bf._size = old_size;
@ -194,7 +214,7 @@ _DEFUN(fread, (buf, size, count, fp),
/* fp->_r = 0 ... done in __srefill */ /* fp->_r = 0 ... done in __srefill */
p += r; p += r;
resid -= r; resid -= r;
if (__srefill (fp)) if (__srefill_r (ptr, fp))
{ {
/* no more input: return partial result */ /* no more input: return partial result */
#ifdef __SCLE #ifdef __SCLE
@ -224,3 +244,15 @@ _DEFUN(fread, (buf, size, count, fp),
_funlockfile (fp); _funlockfile (fp);
return count; return count;
} }
#ifndef _REENT_ONLY
size_t
_DEFUN(fread, (buf, size, count, fp),
_PTR buf _AND
size_t size _AND
size_t count _AND
FILE * fp)
{
return _fread_r (_REENT, buf, size, count, fp);
}
#endif

View File

@ -333,7 +333,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
n = target - curoff; n = target - curoff;
if (n) if (n)
{ {
if (__srefill (fp) || fp->_r < n) if (__srefill_r (ptr, fp) || fp->_r < n)
goto dumb; goto dumb;
fp->_p += n; fp->_p += n;
fp->_r -= n; fp->_r -= n;

View File

@ -20,6 +20,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h>
#include "local.h" #include "local.h"
#include "fvwrite.h" #include "fvwrite.h"
@ -43,7 +44,8 @@
*/ */
int int
_DEFUN(__sfvwrite, (fp, uio), _DEFUN(__sfvwrite_r, (ptr, fp, uio),
struct _reent *ptr _AND
register FILE *fp _AND register FILE *fp _AND
register struct __suio *uio) register struct __suio *uio)
{ {
@ -59,7 +61,11 @@ _DEFUN(__sfvwrite, (fp, uio),
/* make sure we can write */ /* make sure we can write */
if (cantwrite (fp)) if (cantwrite (fp))
return EOF; {
fp->_flags |= __SERR;
ptr->_errno = EBADF;
return EOF;
}
iov = uio->uio_iov; iov = uio->uio_iov;
len = 0; len = 0;

View File

@ -19,7 +19,7 @@
#include <_ansi.h> #include <_ansi.h>
/* /*
* I/O descriptors for __sfvwrite(). * I/O descriptors for __sfvwrite_r().
*/ */
struct __siov { struct __siov {
_CONST _PTR iov_base; _CONST _PTR iov_base;
@ -32,7 +32,7 @@ struct __suio {
}; };
extern int _EXFUN(__sfvwrite,(FILE *, struct __suio *)); extern int _EXFUN(__sfvwrite_r,(struct _reent *, FILE *, struct __suio *));
extern int _EXFUN(__swsetup,(FILE *)); extern int _EXFUN(__swsetup,(FILE *));

View File

@ -21,12 +21,18 @@ FUNCTION
INDEX INDEX
fwrite fwrite
INDEX
_fwrite_r
ANSI_SYNOPSIS ANSI_SYNOPSIS
#include <stdio.h> #include <stdio.h>
size_t fwrite(const void *<[buf]>, size_t <[size]>, size_t fwrite(const void *<[buf]>, size_t <[size]>,
size_t <[count]>, FILE *<[fp]>); size_t <[count]>, FILE *<[fp]>);
#include <stdio.h>
size_t _fwrite_r(struct _reent *<[ptr[>, const void *<[buf]>, size_t <[size]>,
size_t <[count]>, FILE *<[fp]>);
TRAD_SYNOPSIS TRAD_SYNOPSIS
#include <stdio.h> #include <stdio.h>
size_t fwrite(<[buf]>, <[size]>, <[count]>, <[fp]>) size_t fwrite(<[buf]>, <[size]>, <[count]>, <[fp]>)
@ -35,6 +41,14 @@ TRAD_SYNOPSIS
size_t <[count]>; size_t <[count]>;
FILE *<[fp]>; FILE *<[fp]>;
#include <stdio.h>
size_t _fwrite_r(<[ptr]>, <[buf]>, <[size]>, <[count]>, <[fp]>)
struct _reent *<[ptr]>;
char *<[buf]>;
size_t <[size]>;
size_t <[count]>;
FILE *<[fp]>;
DESCRIPTION DESCRIPTION
<<fwrite>> attempts to copy, starting from the memory location <<fwrite>> attempts to copy, starting from the memory location
<[buf]>, <[count]> elements (each of size <[size]>) into the file or <[buf]>, <[count]> elements (each of size <[size]>) into the file or
@ -44,6 +58,9 @@ stream identified by <[fp]>. <<fwrite>> may copy fewer elements than
<<fwrite>> also advances the file position indicator (if any) for <<fwrite>> also advances the file position indicator (if any) for
<[fp]> by the number of @emph{characters} actually written. <[fp]> by the number of @emph{characters} actually written.
<<_fwrite_r>> is simply the reentrant version of <<fwrite>> that
takes an additional reentrant structure argument: <[ptr]>.
RETURNS RETURNS
If <<fwrite>> succeeds in writing all the elements you specify, the If <<fwrite>> succeeds in writing all the elements you specify, the
result is the same as the argument <[count]>. In any event, the result is the same as the argument <[count]>. In any event, the
@ -78,7 +95,8 @@ static char sccsid[] = "%W% (Berkeley) %G%";
*/ */
size_t size_t
_DEFUN(fwrite, (buf, size, count, fp), _DEFUN(_fwrite_r, (ptr, buf, size, count, fp),
struct _reent * ptr _AND
_CONST _PTR buf _AND _CONST _PTR buf _AND
size_t size _AND size_t size _AND
size_t count _AND size_t count _AND
@ -94,15 +112,15 @@ _DEFUN(fwrite, (buf, size, count, fp),
uio.uio_iovcnt = 1; uio.uio_iovcnt = 1;
/* /*
* The usual case is success (__sfvwrite returns 0); * The usual case is success (__sfvwrite_r returns 0);
* skip the divide if this happens, since divides are * skip the divide if this happens, since divides are
* generally slow and since this occurs whenever size==0. * generally slow and since this occurs whenever size==0.
*/ */
CHECK_INIT(_REENT); CHECK_INIT(ptr);
_flockfile (fp); _flockfile (fp);
if (__sfvwrite (fp, &uio) == 0) if (__sfvwrite_r (ptr, fp, &uio) == 0)
{ {
_funlockfile (fp); _funlockfile (fp);
return count; return count;
@ -110,3 +128,15 @@ _DEFUN(fwrite, (buf, size, count, fp),
_funlockfile (fp); _funlockfile (fp);
return (n - uio.uio_resid) / size; return (n - uio.uio_resid) / size;
} }
#ifndef _REENT_ONLY
size_t
_DEFUN(fwrite, (buf, size, count, fp),
_CONST _PTR buf _AND
size_t size _AND
size_t count _AND
FILE * fp)
{
return _fwrite_r (_REENT, buf, size, count, fp);
}
#endif

View File

@ -21,16 +21,26 @@ FUNCTION
INDEX INDEX
getc getc
INDEX
_getc_r
ANSI_SYNOPSIS ANSI_SYNOPSIS
#include <stdio.h> #include <stdio.h>
int getc(FILE *<[fp]>); int getc(FILE *<[fp]>);
#include <stdio.h>
int _getc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
TRAD_SYNOPSIS TRAD_SYNOPSIS
#include <stdio.h> #include <stdio.h>
int getc(<[fp]>) int getc(<[fp]>)
FILE *<[fp]>; FILE *<[fp]>;
#include <stdio.h>
int _getc_r(<[ptr]>, <[fp]>)
struct _reent *<[ptr]>;
FILE *<[fp]>;
DESCRIPTION DESCRIPTION
<<getc>> is a macro, defined in <<stdio.h>>. You can use <<getc>> <<getc>> is a macro, defined in <<stdio.h>>. You can use <<getc>>
to get the next single character from the file or stream to get the next single character from the file or stream
@ -39,6 +49,9 @@ current position indicator.
For a subroutine version of this macro, see <<fgetc>>. For a subroutine version of this macro, see <<fgetc>>.
The <<_getc_r>> function is simply the reentrant version of <<getc>>
which passes an additional reentrancy structure pointer argument: <[ptr]>.
RETURNS RETURNS
The next character (read as an <<unsigned char>>, and cast to The next character (read as an <<unsigned char>>, and cast to
<<int>>), unless there is no more data, or the host system reports a <<int>>), unless there is no more data, or the host system reports a
@ -72,6 +85,21 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#undef getc #undef getc
int
_DEFUN(_getc_r, (ptr, fp),
struct _reent *ptr _AND
register FILE *fp)
{
int result;
CHECK_INIT (ptr);
_flockfile (fp);
result = __sgetc_r (ptr, fp);
_funlockfile (fp);
return result;
}
#ifndef _REENT_ONLY
int int
_DEFUN(getc, (fp), _DEFUN(getc, (fp),
register FILE *fp) register FILE *fp)
@ -79,7 +107,9 @@ _DEFUN(getc, (fp),
int result; int result;
CHECK_INIT (_REENT); CHECK_INIT (_REENT);
_flockfile (fp); _flockfile (fp);
result = __sgetc (fp); result = __sgetc_r (_REENT, fp);
_funlockfile (fp); _funlockfile (fp);
return result; return result;
} }
#endif /* !_REENT_ONLY */

View File

@ -21,11 +21,16 @@ FUNCTION
INDEX INDEX
getc_unlocked getc_unlocked
INDEX
_getc_unlocked_r
POSIX_SYNOPSIS POSIX_SYNOPSIS
#include <stdio.h> #include <stdio.h>
int getc_unlocked(FILE *<[fp]>); int getc_unlocked(FILE *<[fp]>);
#include <stdio.h>
int _getc_unlocked_r(FILE *<[fp]>);
DESCRIPTION DESCRIPTION
<<getc_unlocked>> is a non-thread-safe version of <<getc>> declared in <<getc_unlocked>> is a non-thread-safe version of <<getc>> declared in
<<stdio.h>>. <<getc_unlocked>> may only safely be used within a scope <<stdio.h>>. <<getc_unlocked>> may only safely be used within a scope
@ -36,6 +41,10 @@ object, as is the case after a successful call to the flockfile() or
ftrylockfile() functions. If threads are disabled, then ftrylockfile() functions. If threads are disabled, then
<<getc_unlocked>> is equivalent to <<getc>>. <<getc_unlocked>> is equivalent to <<getc>>.
The <<_getc_unlocked_r>> function is simply the reentrant version of
<<get_unlocked>> which passes an additional reentrancy structure pointer
argument: <[ptr]>.
RETURNS RETURNS
See <<getc>>. See <<getc>>.
@ -59,11 +68,23 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#undef getc_unlocked #undef getc_unlocked
int
_DEFUN(_getc_unlocked_r, (ptr, fp),
struct _reent *ptr _AND
register FILE *fp)
{
/* CHECK_INIT is called (eventually) by __srefill_r. */
return __sgetc_r (ptr, fp);
}
#ifndef _REENT_ONLY
int int
_DEFUN(getc_unlocked, (fp), _DEFUN(getc_unlocked, (fp),
register FILE *fp) register FILE *fp)
{ {
/* CHECK_INIT is called (eventually) by __srefill. */ return __sgetc_r (_REENT, fp);
return __sgetc (fp);
} }
#endif /* !_REENT_ONLY */

View File

@ -79,11 +79,11 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#undef getchar #undef getchar
int int
_DEFUN(_getchar_r, (f), _DEFUN(_getchar_r, (reent),
struct _reent *f) struct _reent *reent)
{ {
_REENT_SMALL_CHECK_INIT (f); _REENT_SMALL_CHECK_INIT (reent);
return getc (_stdin_r (f)); return _getc_r (reent, _stdin_r (reent));
} }
#ifndef _REENT_ONLY #ifndef _REENT_ONLY
@ -91,9 +91,9 @@ _DEFUN(_getchar_r, (f),
int int
_DEFUN_VOID(getchar) _DEFUN_VOID(getchar)
{ {
/* CHECK_INIT is called (eventually) by __srefill. */ /* CHECK_INIT is called (eventually) by __srefill_r. */
_REENT_SMALL_CHECK_INIT (_REENT);
return _getchar_r (_REENT); return _getc_r (_REENT, _stdin_r (_REENT));
} }
#endif #endif

View File

@ -21,11 +21,16 @@ FUNCTION
INDEX INDEX
getchar_unlocked getchar_unlocked
INDEX
_getchar_unlocked_r
POSIX_SYNOPSIS POSIX_SYNOPSIS
#include <stdio.h> #include <stdio.h>
int getchar_unlocked(); int getchar_unlocked();
#include <stdio.h>
int _getchar_unlocked_r(struct _reent *<[ptr]>);
DESCRIPTION DESCRIPTION
<<getchar_unlocked>> is a non-thread-safe version of <<getchar>> <<getchar_unlocked>> is a non-thread-safe version of <<getchar>>
declared in <<stdio.h>>. <<getchar_unlocked>> may only safely be used declared in <<stdio.h>>. <<getchar_unlocked>> may only safely be used
@ -36,6 +41,10 @@ the ( FILE *) object, as is the case after a successful call to the
flockfile() or ftrylockfile() functions. If threads are disabled, flockfile() or ftrylockfile() functions. If threads are disabled,
then <<getchar_unlocked>> is equivalent to <<getchar>>. then <<getchar_unlocked>> is equivalent to <<getchar>>.
The <<_getchar_unlocked_r>> function is simply the reentrant version of
<<getchar_unlocked>> which passes an addtional reentrancy structure pointer
argument: <[ptr]>.
RETURNS RETURNS
See <<getchar>>. See <<getchar>>.
@ -61,10 +70,10 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#undef getchar_unlocked #undef getchar_unlocked
int int
_DEFUN(_getchar_unlocked_r, (f), _DEFUN(_getchar_unlocked_r, (ptr),
struct _reent *f) struct _reent *ptr)
{ {
return getc_unlocked (_stdin_r (f)); return _getc_unlocked_r (ptr, _stdin_r (ptr));
} }
#ifndef _REENT_ONLY #ifndef _REENT_ONLY
@ -72,9 +81,9 @@ _DEFUN(_getchar_unlocked_r, (f),
int int
_DEFUN_VOID(getchar_unlocked) _DEFUN_VOID(getchar_unlocked)
{ {
/* CHECK_INIT is called (eventually) by __srefill. */ /* CHECK_INIT is called (eventually) by __srefill_r. */
return _getchar_unlocked_r (_REENT); return _getc_unlocked_r (_REENT, _stdin_r (_REENT));
} }
#endif #endif

View File

@ -33,7 +33,7 @@ extern int _EXFUN(__svfscanf_r,(struct _reent *,FILE *, _CONST char *,va_list
extern int _EXFUN(__svfiscanf_r,(struct _reent *,FILE *, _CONST char *,va_list)); extern int _EXFUN(__svfiscanf_r,(struct _reent *,FILE *, _CONST char *,va_list));
extern FILE *_EXFUN(__sfp,(struct _reent *)); extern FILE *_EXFUN(__sfp,(struct _reent *));
extern int _EXFUN(__sflags,(struct _reent *,_CONST char*, int*)); extern int _EXFUN(__sflags,(struct _reent *,_CONST char*, int*));
extern int _EXFUN(__srefill,(FILE *)); extern int _EXFUN(__srefill_r,(struct _reent *,FILE *));
extern _READ_WRITE_RETURN_TYPE _EXFUN(__sread,(_PTR, char *, int)); extern _READ_WRITE_RETURN_TYPE _EXFUN(__sread,(_PTR, char *, int));
extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite,(_PTR, char _CONST *, int)); extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite,(_PTR, char _CONST *, int));
extern _fpos_t _EXFUN(__sseek,(_PTR, _fpos_t, int)); extern _fpos_t _EXFUN(__sseek,(_PTR, _fpos_t, int));
@ -45,7 +45,6 @@ extern _VOID _EXFUN(__smakebuf,(FILE *));
extern int _EXFUN(_fwalk,(struct _reent *, int (*)(FILE *))); extern int _EXFUN(_fwalk,(struct _reent *, int (*)(FILE *)));
extern int _EXFUN(_fwalk_reent,(struct _reent *, int (*)(struct _reent *, FILE *))); extern int _EXFUN(_fwalk_reent,(struct _reent *, int (*)(struct _reent *, FILE *)));
struct _glue * _EXFUN(__sfmoreglue,(struct _reent *,int n)); struct _glue * _EXFUN(__sfmoreglue,(struct _reent *,int n));
extern int _EXFUN(__srefill,(FILE *fp));
/* Called by the main entry point fns to ensure stdio has been initialized. */ /* Called by the main entry point fns to ensure stdio has been initialized. */

View File

@ -21,17 +21,28 @@ FUNCTION
INDEX INDEX
putc putc
INDEX
_putc_r
ANSI_SYNOPSIS ANSI_SYNOPSIS
#include <stdio.h> #include <stdio.h>
int putc(int <[ch]>, FILE *<[fp]>); int putc(int <[ch]>, FILE *<[fp]>);
#include <stdio.h>
int _putc_r(struct _reent *<[ptr]>, int <[ch]>, FILE *<[fp]>);
TRAD_SYNOPSIS TRAD_SYNOPSIS
#include <stdio.h> #include <stdio.h>
int putc(<[ch]>, <[fp]>) int putc(<[ch]>, <[fp]>)
int <[ch]>; int <[ch]>;
FILE *<[fp]>; FILE *<[fp]>;
#include <stdio.h>
int _putc_r(<[ptr]>, <[ch]>, <[fp]>)
struct _reent *<[ptr]>;
int <[ch]>;
FILE *<[fp]>;
DESCRIPTION DESCRIPTION
<<putc>> is a macro, defined in <<stdio.h>>. <<putc>> <<putc>> is a macro, defined in <<stdio.h>>. <<putc>>
writes the argument <[ch]> to the file or stream identified by writes the argument <[ch]> to the file or stream identified by
@ -45,6 +56,9 @@ advances by one.
For a subroutine version of this macro, see <<fputc>>. For a subroutine version of this macro, see <<fputc>>.
The <<_putc_r>> function is simply the reentrant version of
<<putc>> that takes an additional reentrant structure argument: <[ptr]>.
RETURNS RETURNS
If successful, <<putc>> returns its argument <[ch]>. If an error If successful, <<putc>> returns its argument <[ch]>. If an error
intervenes, the result is <<EOF>>. You can use `<<ferror(<[fp]>)>>' to intervenes, the result is <<EOF>>. You can use `<<ferror(<[fp]>)>>' to
@ -76,14 +90,35 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#undef putc #undef putc
int int
_DEFUN(putc, (c, fp), _DEFUN(_putc_r, (ptr, c, fp),
struct _reent *ptr _AND
int c _AND int c _AND
register FILE *fp) register FILE *fp)
{ {
int result; int result;
CHECK_INIT (_REENT); CHECK_INIT (ptr);
_flockfile (fp); _flockfile (fp);
result = __sputc (c, fp); result = __sputc_r (ptr, c, fp);
_funlockfile (fp); _funlockfile (fp);
return result; return result;
} }
#ifndef _REENT_ONLY
int
_DEFUN(putc, (c, fp),
int c _AND
register FILE *fp)
{
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
int result;
CHECK_INIT (_REENT);
_flockfile (fp);
result = __sputc_r (_REENT, c, fp);
_funlockfile (fp);
return result;
#else
return _putc_r (_REENT, c, fp);
#endif
}
#endif /* !_REENT_ONLY */

View File

@ -21,11 +21,16 @@ FUNCTION
INDEX INDEX
putc_unlocked putc_unlocked
INDEX
_putc_unlocked_r
POSIX_SYNOPSIS POSIX_SYNOPSIS
#include <stdio.h> #include <stdio.h>
int putc_unlocked(int <[ch]>, FILE *<[fp]>); int putc_unlocked(int <[ch]>, FILE *<[fp]>);
#include <stdio.h>
int _putc_unlocked_r(struct _reent *<[ptr]>, int <[ch]>, FILE *<[fp]>);
DESCRIPTION DESCRIPTION
<<putc_unlocked>> is a non-thread-safe version of <<putc>> declared in <<putc_unlocked>> is a non-thread-safe version of <<putc>> declared in
<<stdio.h>>. <<putc_unlocked>> may only safely be used within a scope <<stdio.h>>. <<putc_unlocked>> may only safely be used within a scope
@ -36,6 +41,10 @@ object, as is the case after a successful call to the flockfile() or
ftrylockfile() functions. If threads are disabled, then ftrylockfile() functions. If threads are disabled, then
<<putc_unlocked>> is equivalent to <<putc>>. <<putc_unlocked>> is equivalent to <<putc>>.
The function <<_putc_unlocked_r>> is simply the reentrant version of
<<putc_unlocked>> that takes an additional reentrant structure pointer
argument: <[ptr]>.
RETURNS RETURNS
See <<putc>>. See <<putc>>.
@ -60,6 +69,18 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#undef putc_unlocked #undef putc_unlocked
int
_DEFUN(_putc_unlocked_r, (ptr, c, fp),
struct _reent *ptr _AND
int c _AND
register FILE *fp)
{
/* CHECK_INIT is (eventually) called by __swbuf. */
return __sputc_r (ptr, c, fp);
}
#ifndef _REENT_ONLY
int int
_DEFUN(putc_unlocked, (c, fp), _DEFUN(putc_unlocked, (c, fp),
int c _AND int c _AND
@ -67,5 +88,6 @@ _DEFUN(putc_unlocked, (c, fp),
{ {
/* CHECK_INIT is (eventually) called by __swbuf. */ /* CHECK_INIT is (eventually) called by __swbuf. */
return __sputc (c, fp); return __sputc_r (_REENT, c, fp);
} }
#endif /* !_REENT_ONLY */

View File

@ -81,7 +81,7 @@ _DEFUN(_putchar_r, (ptr, c),
int c) int c)
{ {
_REENT_SMALL_CHECK_INIT (ptr); _REENT_SMALL_CHECK_INIT (ptr);
return putc (c, _stdout_r (ptr)); return _putc_r (ptr, c, _stdout_r (ptr));
} }
#ifndef _REENT_ONLY #ifndef _REENT_ONLY
@ -90,9 +90,8 @@ int
_DEFUN(putchar, (c), _DEFUN(putchar, (c),
int c) int c)
{ {
/* CHECK_INIT is (eventually) called by __swbuf. */ _REENT_SMALL_CHECK_INIT (_REENT);
return _putc_r (_REENT, c, _stdout_r (_REENT));
return _putchar_r (_REENT, c);
} }
#endif #endif

View File

@ -91,7 +91,7 @@ _DEFUN(_puts_r, (ptr, s),
uio.uio_iovcnt = 2; uio.uio_iovcnt = 2;
_REENT_SMALL_CHECK_INIT (ptr); _REENT_SMALL_CHECK_INIT (ptr);
return (__sfvwrite (_stdout_r (ptr), &uio) ? EOF : '\n'); return (__sfvwrite_r (ptr, _stdout_r (ptr), &uio) ? EOF : '\n');
} }
#ifndef _REENT_ONLY #ifndef _REENT_ONLY

View File

@ -19,6 +19,7 @@
#include <_ansi.h> #include <_ansi.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h>
#include "local.h" #include "local.h"
static int static int
@ -36,7 +37,8 @@ _DEFUN(lflush, (fp),
*/ */
int int
_DEFUN(__srefill, (fp), _DEFUN(__srefill_r, (ptr, fp),
struct _reent * ptr _AND
register FILE * fp) register FILE * fp)
{ {
/* make sure stdio is set up */ /* make sure stdio is set up */
@ -55,7 +57,11 @@ _DEFUN(__srefill, (fp),
if ((fp->_flags & __SRD) == 0) if ((fp->_flags & __SRD) == 0)
{ {
if ((fp->_flags & __SRW) == 0) if ((fp->_flags & __SRW) == 0)
return EOF; {
ptr->_errno = EBADF;
fp->_flags |= __SERR;
return EOF;
}
/* switch to reading */ /* switch to reading */
if (fp->_flags & __SWR) if (fp->_flags & __SWR)
{ {

View File

@ -22,6 +22,7 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#include <_ansi.h> #include <_ansi.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#include "local.h" #include "local.h"
/* /*
@ -31,10 +32,11 @@ static char sccsid[] = "%W% (Berkeley) %G%";
*/ */
int int
_DEFUN(__srget, (fp), _DEFUN(__srget_r, (ptr, fp),
struct _reent *ptr _AND
register FILE *fp) register FILE *fp)
{ {
if (__srefill (fp) == 0) if (__srefill_r (ptr, fp) == 0)
{ {
fp->_r--; fp->_r--;
return *fp->_p++; return *fp->_p++;

View File

@ -212,7 +212,8 @@ static char *rcsid = "$Id$";
* then reset it so that it can be reused. * then reset it so that it can be reused.
*/ */
static int static int
_DEFUN(__sprint, (fp, uio), _DEFUN(__sprint_r, (ptr, fp, uio),
struct _reent *ptr _AND
FILE *fp _AND FILE *fp _AND
register struct __suio *uio) register struct __suio *uio)
{ {
@ -222,7 +223,7 @@ _DEFUN(__sprint, (fp, uio),
uio->uio_iovcnt = 0; uio->uio_iovcnt = 0;
return (0); return (0);
} }
err = __sfvwrite(fp, uio); err = __sfvwrite_r(ptr, fp, uio);
uio->uio_resid = 0; uio->uio_resid = 0;
uio->uio_iovcnt = 0; uio->uio_iovcnt = 0;
return (err); return (err);
@ -469,7 +470,7 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap),
uio.uio_resid += (len); \ uio.uio_resid += (len); \
iovp++; \ iovp++; \
if (++uio.uio_iovcnt >= NIOV) { \ if (++uio.uio_iovcnt >= NIOV) { \
if (__sprint(fp, &uio)) \ if (__sprint_r(data, fp, &uio)) \
goto error; \ goto error; \
iovp = iov; \ iovp = iov; \
} \ } \
@ -484,7 +485,7 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap),
} \ } \
} }
#define FLUSH() { \ #define FLUSH() { \
if (uio.uio_resid && __sprint(fp, &uio)) \ if (uio.uio_resid && __sprint_r(data, fp, &uio)) \
goto error; \ goto error; \
uio.uio_iovcnt = 0; \ uio.uio_iovcnt = 0; \
iovp = iov; \ iovp = iov; \

View File

@ -221,7 +221,7 @@ typedef unsigned long long u_long_long;
* vfscanf * vfscanf
*/ */
#define BufferEmpty (fp->_r <= 0 && __srefill(fp)) #define BufferEmpty (fp->_r <= 0 && __srefill_r(rptr, fp))
#ifndef _REENT_ONLY #ifndef _REENT_ONLY
@ -547,7 +547,7 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap),
if (--fp->_r > 0) if (--fp->_r > 0)
fp->_p++; fp->_p++;
else else
if (__srefill (fp)) if (__srefill_r (rptr, fp))
goto input_failure; goto input_failure;
} }
/* /*
@ -615,7 +615,7 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap),
sum += n; sum += n;
width -= n; width -= n;
fp->_p += n; fp->_p += n;
if (__srefill (fp)) if (__srefill_r (rptr, fp))
{ {
if (sum == 0) if (sum == 0)
goto input_failure; goto input_failure;
@ -910,7 +910,7 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap),
if (--fp->_r > 0) if (--fp->_r > 0)
fp->_p++; fp->_p++;
else else
if (__srefill (fp)) if (__srefill_r (rptr, fp))
break; /* EOF */ break; /* EOF */
} }
/* /*
@ -1107,7 +1107,7 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap),
if (--fp->_r > 0) if (--fp->_r > 0)
fp->_p++; fp->_p++;
else else
if (__srefill (fp)) if (__srefill_r (rptr, fp))
break; /* EOF */ break; /* EOF */
} }
if (zeroes) if (zeroes)

View File

@ -22,6 +22,7 @@ static char sccsid[] = "%W% (Berkeley) %G%";
#include <_ansi.h> #include <_ansi.h>
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#include "local.h" #include "local.h"
#include "fvwrite.h" #include "fvwrite.h"
@ -32,7 +33,8 @@ static char sccsid[] = "%W% (Berkeley) %G%";
*/ */
int int
_DEFUN(__swbuf, (c, fp), _DEFUN(__swbuf_r, (ptr, c, fp),
struct _reent *ptr _AND
register int c _AND register int c _AND
register FILE *fp) register FILE *fp)
{ {
@ -40,7 +42,7 @@ _DEFUN(__swbuf, (c, fp),
/* Ensure stdio has been initialized. */ /* Ensure stdio has been initialized. */
CHECK_INIT (_REENT); CHECK_INIT (ptr);
/* /*
* In case we cannot write, or longjmp takes us out early, * In case we cannot write, or longjmp takes us out early,
@ -52,7 +54,11 @@ _DEFUN(__swbuf, (c, fp),
fp->_w = fp->_lbfsize; fp->_w = fp->_lbfsize;
if (cantwrite (fp)) if (cantwrite (fp))
return EOF; {
fp->_flags |= __SERR;
ptr->_errno = EBADF;
return EOF;
}
c = (unsigned char) c; c = (unsigned char) c;
/* /*

View File

@ -309,7 +309,7 @@ _DEFUN (_fseeko64_r, (ptr, fp, offset, whence),
n = target - curoff; n = target - curoff;
if (n) if (n)
{ {
if (__srefill (fp) || fp->_r < n) if (__srefill_r (ptr, fp) || fp->_r < n)
goto dumb; goto dumb;
fp->_p += n; fp->_p += n;
fp->_r -= n; fp->_r -= n;

View File

@ -1,3 +1,5 @@
#if 0 /* We don't need this file because math.h defines these values. */
/* `HUGE_VAL' constants for ix86 (where it is infinity). /* `HUGE_VAL' constants for ix86 (where it is infinity).
Used by <stdlib.h> and <math.h> functions for overflow. Used by <stdlib.h> and <math.h> functions for overflow.
Copyright (C) 1992, 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc. Copyright (C) 1992, 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
@ -54,3 +56,4 @@ static __huge_vall_t __huge_vall = { __HUGE_VALL_bytes };
# endif /* GCC 2.95 */ # endif /* GCC 2.95 */
#endif /* if 0 */