+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>
* /libc/sys/arm/syscalls.c (_unlink, isatty, _system, _rename):
FILE * _EXFUN(_fdopen_r, (struct _reent *, int, const char *));
FILE * _EXFUN(_fopen_r, (struct _reent *, const char *, const char *));
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(_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(_fseek_r, (struct _reent *, FILE *, long, int));
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_unlocked_r, (struct _reent *));
char * _EXFUN(_gets_r, (struct _reent *, char *));
int _EXFUN(_iprintf_r, (struct _reent *, const char *, ...));
int _EXFUN(_iscanf_r, (struct _reent *, const char *, ...));
char * _EXFUN(_mktemp_r, (struct _reent *, char *));
void _EXFUN(_perror_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(_puts_r, (struct _reent *, const char *));
int _EXFUN(_remove_r, (struct _reent *, const char *));
* Routines internal to the implementation.
*/
-int _EXFUN(__srget, (FILE *));
-int _EXFUN(__swbuf, (int, FILE *));
+int _EXFUN(__srget_r, (struct _reent *, FILE *));
+int _EXFUN(__swbuf_r, (struct _reent *, int, FILE *));
/*
* Stdio function-access interface.
* The __sfoo macros are here so that we can
* 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
-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'))
{
- int __c2 = __sgetc_raw(__p);
+ int __c2 = __sgetc_raw_r(__ptr, __p);
if (__c2 == '\n')
__c = __c2;
else
return __c;
}
#else
-#define __sgetc(p) __sgetc_raw(p)
+#define __sgetc_r(__ptr, __p) __sgetc_raw_r(__ptr, __p)
#endif
#ifdef _never /* __GNUC__ */
/* If this inline is actually used, then systems using coff debugging
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'))
return (*_p->_p++ = _c);
else
- return (__swbuf(_c, _p));
+ return (__swbuf_r(_ptr, _c, _p));
}
#else
/*
* This has been tuned to generate reasonable code on the vax using pcc
*/
-#define __sputc_raw(c, p) \
- (--(p)->_w < 0 ? \
- (p)->_w >= (p)->_lbfsize ? \
- (*(p)->_p = (c)), *(p)->_p != '\n' ? \
- (int)*(p)->_p++ : \
- __swbuf('\n', p) : \
- __swbuf((int)(c), p) : \
- (*(p)->_p = (c), (int)*(p)->_p++))
+#define __sputc_raw_r(__ptr, __c, __p) \
+ (--(__p)->_w < 0 ? \
+ (__p)->_w >= (__p)->_lbfsize ? \
+ (*(__p)->_p = (__c)), *(__p)->_p != '\n' ? \
+ (int)*(__p)->_p++ : \
+ __swbuf_r(__ptr, '\n', __p) : \
+ __swbuf_r(__ptr, (int)(__c), __p) : \
+ (*(__p)->_p = (__c), (int)*(__p)->_p++))
#ifdef __SCLE
-#define __sputc(c, p) \
- ((((p)->_flags & __SCLE) && ((c) == '\n')) \
- ? __sputc_raw('\r', (p)) : 0 , \
- __sputc_raw((c), (p)))
+#define __sputc_r(__ptr, __c, __p) \
+ ((((__p)->_flags & __SCLE) && ((__c) == '\n')) \
+ ? __sputc_raw_r(__ptr, '\r', (__p)) : 0 , \
+ __sputc_raw_r((__ptr), (__c), (__p)))
#else
-#define __sputc(c, p) __sputc_raw(c, p)
+#define __sputc_r(__ptr, __c, __p) __sputc_raw_r(__ptr, __c, __p)
#endif
#endif
#ifndef __CYGWIN__
#ifndef lint
-#define getc(fp) __sgetc(fp)
-#define putc(x, fp) __sputc(x, fp)
+#define getc(fp) __sgetc_r(_REENT, fp)
+#define putc(x, fp) __sputc_r(_REENT, x, fp)
#endif /* lint */
#endif /* __CYGWIN__ */
#ifndef __STRICT_ANSI__
/* fast always-buffered version, true iff error */
#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 :( */
#ifdef __CYGWIN__
INDEX
fgetc
+INDEX
+ _fgetc_r
ANSI_SYNOPSIS
#include <stdio.h>
int fgetc(FILE *<[fp]>);
+ #include <stdio.h>
+ int _fgetc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
+
TRAD_SYNOPSIS
#include <stdio.h>
int fgetc(<[fp]>)
FILE *<[fp]>;
+ #include <stdio.h>
+ int _fgetc_r(<[ptr]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ FILE *<[fp]>;
+
DESCRIPTION
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
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
The next character (read as an <<unsigned char>>, and cast to
<<int>>), unless there is no more data, or the host system reports a
#include <stdio.h>
#include "local.h"
+int
+_DEFUN(_fgetc_r, (ptr, fp),
+ struct _reent * ptr _AND
+ FILE * fp)
+{
+ int result;
+ CHECK_INIT(ptr);
+ _flockfile (fp);
+ result = __sgetc_r (ptr, fp);
+ _funlockfile (fp);
+ 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 (fp);
+ result = __sgetc_r (_REENT, fp);
_funlockfile (fp);
return result;
+#else
+ return _fgetc_r (_REENT, fp);
+#endif
}
+
+#endif /* !_REENT_ONLY */
+
INDEX
fgets
+INDEX
+ _fgets_r
ANSI_SYNOPSIS
#include <stdio.h>
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
#include <stdio.h>
char *fgets(<[buf]>,<[n]>,<[fp]>)
int <[n]>;
FILE *<[fp]>;
+ #include <stdio.h>
+ char *_fgets_r(<[ptr]>, <[buf]>,<[n]>,<[fp]>)
+ struct _reent *<[ptr]>;
+ char *<[buf]>;
+ int <[n]>;
+ FILE *<[fp]>;
+
DESCRIPTION
Reads at most <[n-1]> characters from <[fp]> until a newline
is found. The characters including to the newline are stored
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
<<fgets>> returns the buffer passed to it, with the data
*/
char *
-_DEFUN(fgets, (buf, n, fp),
+_DEFUN(_fgets_r, (ptr, buf, n, fp),
+ struct _reent * ptr _AND
char *buf _AND
int n _AND
FILE * fp)
s = buf;
- CHECK_INIT(_REENT);
+ CHECK_INIT(ptr);
_flockfile (fp);
#ifdef __SCLE
{
int c;
/* 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;
if (c == '\n')
*/
if ((len = fp->_r) <= 0)
{
- if (__srefill (fp))
+ if (__srefill_r (ptr, fp))
{
/* EOF: stop with partial or no line */
if (s == buf)
_funlockfile (fp);
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 */
INDEX
fputc
+INDEX
+ _fputc_r
ANSI_SYNOPSIS
#include <stdio.h>
int fputc(int <[ch]>, FILE *<[fp]>);
+ #include <stdio.h>
+ int _fputc_r(struct _rent *<[ptr]>, int <[ch]>, FILE *<[fp]>);
+
TRAD_SYNOPSIS
#include <stdio.h>
int fputc(<[ch]>, <[fp]>)
int <[ch]>;
FILE *<[fp]>;
+ #include <stdio.h>
+ int _fputc_r(<[ptr]>, <[ch]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ int <[ch]>;
+ FILE *<[fp]>;
+
DESCRIPTION
<<fputc>> converts the argument <[ch]> from an <<int>> to an
<<unsigned char>>, then writes it to the file or stream identified by
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
If successful, <<fputc>> returns its argument <[ch]>. If an error
intervenes, the result is <<EOF>>. You can use `<<ferror(<[fp]>)>>' to
#include <stdio.h>
#include "local.h"
+int
+_DEFUN(_fputc_r, (ptr, ch, file),
+ struct _reent *ptr _AND
+ int ch _AND
+ FILE * file)
+{
+ int result;
+ CHECK_INIT(ptr);
+ _flockfile (file);
+ result = _putc_r (ptr, ch, file);
+ _funlockfile (file);
+ 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 (ch, file);
+ result = _putc_r (_REENT, ch, file);
_funlockfile (file);
return result;
+#else
+ return _fputc_r (_REENT, ch, file);
+#endif
}
+#endif /* !_REENT_ONLY */
INDEX
fputs
+INDEX
+ _fputs_r
ANSI_SYNOPSIS
#include <stdio.h>
int fputs(const char *<[s]>, FILE *<[fp]>);
+ #include <stdio.h>
+ int _fputs_r(struct _reent *<[ptr]>, const char *<[s]>, FILE *<[fp]>);
+
TRAD_SYNOPSIS
#include <stdio.h>
int fputs(<[s]>, <[fp]>)
char *<[s]>;
FILE *<[fp]>;
+ #include <stdio.h>
+ int _fputs_r(<[ptr]>, <[s]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ char *<[s]>;
+ FILE *<[fp]>;
+
DESCRIPTION
<<fputs>> writes the string at <[s]> (but without the trailing null)
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
If successful, the result is <<0>>; otherwise, the result is <<EOF>>.
*/
int
-_DEFUN(fputs, (s, fp),
+_DEFUN(_fputs_r, (ptr, s, fp),
+ struct _reent * ptr _AND
char _CONST * s _AND
FILE * fp)
{
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
- CHECK_INIT(_REENT);
+ CHECK_INIT(ptr);
_flockfile (fp);
- result = __sfvwrite (fp, &uio);
+ result = __sfvwrite_r (ptr, fp, &uio);
_funlockfile (fp);
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 */
INDEX
fread
+INDEX
+ _fread_r
ANSI_SYNOPSIS
#include <stdio.h>
size_t fread(void *<[buf]>, size_t <[size]>, size_t <[count]>,
FILE *<[fp]>);
+ #include <stdio.h>
+ size_t _fread_r(struct _reent *<[ptr]>, void *<[buf]>,
+ size_t <[size]>, size_t <[count]>,
+ FILE *<[fp]>);
+
TRAD_SYNOPSIS
#include <stdio.h>
size_t fread(<[buf]>, <[size]>, <[count]>, <[fp]>)
size_t <[count]>;
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
<<fread>> attempts to copy, from the file or stream identified by
<[fp]>, <[count]> elements (each of size <[size]>) into memory,
<<fread>> also advances the file position indicator (if any) for
<[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
The result of <<fread>> is the number of elements it succeeded in
reading.
#ifdef __SCLE
static size_t
-_DEFUN(crlf, (fp, buf, count, eof),
+_DEFUN(crlf_r, (ptr, fp, buf, count, eof),
+ struct _reent * ptr _AND
FILE * fp _AND
char * buf _AND
size_t count _AND
{
if (*s == '\r')
{
- int c = __sgetc_raw (fp);
+ int c = __sgetc_raw_r (ptr, fp);
if (c == '\n')
*s = '\n';
else
while (d < e)
{
- r = getc (fp);
+ r = _getc_r (ptr, fp);
if (r == EOF)
return count - (e-d);
*d++ = r;
#endif
size_t
-_DEFUN(fread, (buf, size, count, fp),
+_DEFUN(_fread_r, (ptr, buf, size, count, fp),
+ struct _reent * ptr _AND
_PTR buf _AND
size_t size _AND
size_t count _AND
if ((resid = count * size) == 0)
return 0;
- CHECK_INIT(_REENT);
+ CHECK_INIT(ptr);
_flockfile (fp);
if (fp->_r < 0)
fp->_bf._base = p;
fp->_bf._size = resid;
fp->_p = p;
- rc = __srefill (fp);
+ rc = __srefill_r (ptr, fp);
/* restore fp buffering back to original state */
fp->_bf._base = old_base;
fp->_bf._size = old_size;
/* fp->_r = 0 ... done in __srefill */
p += r;
resid -= r;
- if (__srefill (fp))
+ if (__srefill_r (ptr, fp))
{
/* no more input: return partial result */
#ifdef __SCLE
_funlockfile (fp);
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
n = target - curoff;
if (n)
{
- if (__srefill (fp) || fp->_r < n)
+ if (__srefill_r (ptr, fp) || fp->_r < n)
goto dumb;
fp->_p += n;
fp->_r -= n;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <errno.h>
#include "local.h"
#include "fvwrite.h"
*/
int
-_DEFUN(__sfvwrite, (fp, uio),
+_DEFUN(__sfvwrite_r, (ptr, fp, uio),
+ struct _reent *ptr _AND
register FILE *fp _AND
register struct __suio *uio)
{
/* make sure we can write */
if (cantwrite (fp))
- return EOF;
+ {
+ fp->_flags |= __SERR;
+ ptr->_errno = EBADF;
+ return EOF;
+ }
iov = uio->uio_iov;
len = 0;
#include <_ansi.h>
/*
- * I/O descriptors for __sfvwrite().
+ * I/O descriptors for __sfvwrite_r().
*/
struct __siov {
_CONST _PTR iov_base;
};
-extern int _EXFUN(__sfvwrite,(FILE *, struct __suio *));
+extern int _EXFUN(__sfvwrite_r,(struct _reent *, FILE *, struct __suio *));
extern int _EXFUN(__swsetup,(FILE *));
INDEX
fwrite
+INDEX
+ _fwrite_r
ANSI_SYNOPSIS
#include <stdio.h>
size_t fwrite(const void *<[buf]>, size_t <[size]>,
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
#include <stdio.h>
size_t fwrite(<[buf]>, <[size]>, <[count]>, <[fp]>)
size_t <[count]>;
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
<<fwrite>> attempts to copy, starting from the memory location
<[buf]>, <[count]> elements (each of size <[size]>) into the file or
<<fwrite>> also advances the file position indicator (if any) for
<[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
If <<fwrite>> succeeds in writing all the elements you specify, the
result is the same as the argument <[count]>. In any event, the
*/
size_t
-_DEFUN(fwrite, (buf, size, count, fp),
+_DEFUN(_fwrite_r, (ptr, buf, size, count, fp),
+ struct _reent * ptr _AND
_CONST _PTR buf _AND
size_t size _AND
size_t count _AND
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
* generally slow and since this occurs whenever size==0.
*/
- CHECK_INIT(_REENT);
+ CHECK_INIT(ptr);
_flockfile (fp);
- if (__sfvwrite (fp, &uio) == 0)
+ if (__sfvwrite_r (ptr, fp, &uio) == 0)
{
_funlockfile (fp);
return count;
_funlockfile (fp);
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
INDEX
getc
+INDEX
+ _getc_r
ANSI_SYNOPSIS
#include <stdio.h>
int getc(FILE *<[fp]>);
+ #include <stdio.h>
+ int _getc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
+
TRAD_SYNOPSIS
#include <stdio.h>
int getc(<[fp]>)
FILE *<[fp]>;
+ #include <stdio.h>
+ int _getc_r(<[ptr]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ FILE *<[fp]>;
+
DESCRIPTION
<<getc>> is a macro, defined in <<stdio.h>>. You can use <<getc>>
to get the next single character from the file or stream
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
The next character (read as an <<unsigned char>>, and cast to
<<int>>), unless there is no more data, or the host system reports a
#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
_DEFUN(getc, (fp),
register FILE *fp)
int result;
CHECK_INIT (_REENT);
_flockfile (fp);
- result = __sgetc (fp);
+ result = __sgetc_r (_REENT, fp);
_funlockfile (fp);
return result;
}
+
+#endif /* !_REENT_ONLY */
INDEX
getc_unlocked
+INDEX
+ _getc_unlocked_r
POSIX_SYNOPSIS
#include <stdio.h>
int getc_unlocked(FILE *<[fp]>);
+ #include <stdio.h>
+ int _getc_unlocked_r(FILE *<[fp]>);
+
DESCRIPTION
<<getc_unlocked>> is a non-thread-safe version of <<getc>> declared in
<<stdio.h>>. <<getc_unlocked>> may only safely be used within a scope
ftrylockfile() functions. If threads are disabled, then
<<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
See <<getc>>.
#undef getc_unlocked
int
-_DEFUN(getc_unlocked, (fp),
+_DEFUN(_getc_unlocked_r, (ptr, fp),
+ struct _reent *ptr _AND
register FILE *fp)
{
- /* CHECK_INIT is called (eventually) by __srefill. */
+ /* CHECK_INIT is called (eventually) by __srefill_r. */
- return __sgetc (fp);
+ return __sgetc_r (ptr, fp);
}
+
+#ifndef _REENT_ONLY
+
+int
+_DEFUN(getc_unlocked, (fp),
+ register FILE *fp)
+{
+ return __sgetc_r (_REENT, fp);
+}
+
+#endif /* !_REENT_ONLY */
#undef getchar
int
-_DEFUN(_getchar_r, (f),
- struct _reent *f)
+_DEFUN(_getchar_r, (reent),
+ struct _reent *reent)
{
- _REENT_SMALL_CHECK_INIT (f);
- return getc (_stdin_r (f));
+ _REENT_SMALL_CHECK_INIT (reent);
+ return _getc_r (reent, _stdin_r (reent));
}
#ifndef _REENT_ONLY
int
_DEFUN_VOID(getchar)
{
- /* CHECK_INIT is called (eventually) by __srefill. */
-
- return _getchar_r (_REENT);
+ /* CHECK_INIT is called (eventually) by __srefill_r. */
+ _REENT_SMALL_CHECK_INIT (_REENT);
+ return _getc_r (_REENT, _stdin_r (_REENT));
}
#endif
INDEX
getchar_unlocked
+INDEX
+ _getchar_unlocked_r
POSIX_SYNOPSIS
#include <stdio.h>
int getchar_unlocked();
+ #include <stdio.h>
+ int _getchar_unlocked_r(struct _reent *<[ptr]>);
+
DESCRIPTION
<<getchar_unlocked>> is a non-thread-safe version of <<getchar>>
declared in <<stdio.h>>. <<getchar_unlocked>> may only safely be used
flockfile() or ftrylockfile() functions. If threads are disabled,
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
See <<getchar>>.
#undef getchar_unlocked
int
-_DEFUN(_getchar_unlocked_r, (f),
- struct _reent *f)
+_DEFUN(_getchar_unlocked_r, (ptr),
+ struct _reent *ptr)
{
- return getc_unlocked (_stdin_r (f));
+ return _getc_unlocked_r (ptr, _stdin_r (ptr));
}
#ifndef _REENT_ONLY
int
_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
extern int _EXFUN(__svfiscanf_r,(struct _reent *,FILE *, _CONST char *,va_list));
extern FILE *_EXFUN(__sfp,(struct _reent *));
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(__swrite,(_PTR, char _CONST *, int));
extern _fpos_t _EXFUN(__sseek,(_PTR, _fpos_t, int));
extern int _EXFUN(_fwalk,(struct _reent *, int (*)(FILE *)));
extern int _EXFUN(_fwalk_reent,(struct _reent *, int (*)(struct _reent *, FILE *)));
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. */
INDEX
putc
+INDEX
+ _putc_r
ANSI_SYNOPSIS
#include <stdio.h>
int putc(int <[ch]>, FILE *<[fp]>);
+ #include <stdio.h>
+ int _putc_r(struct _reent *<[ptr]>, int <[ch]>, FILE *<[fp]>);
+
TRAD_SYNOPSIS
#include <stdio.h>
int putc(<[ch]>, <[fp]>)
int <[ch]>;
FILE *<[fp]>;
+ #include <stdio.h>
+ int _putc_r(<[ptr]>, <[ch]>, <[fp]>)
+ struct _reent *<[ptr]>;
+ int <[ch]>;
+ FILE *<[fp]>;
+
DESCRIPTION
<<putc>> is a macro, defined in <<stdio.h>>. <<putc>>
writes the argument <[ch]> to the file or stream identified by
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
If successful, <<putc>> returns its argument <[ch]>. If an error
intervenes, the result is <<EOF>>. You can use `<<ferror(<[fp]>)>>' to
#undef putc
+int
+_DEFUN(_putc_r, (ptr, c, fp),
+ struct _reent *ptr _AND
+ int c _AND
+ register FILE *fp)
+{
+ int result;
+ CHECK_INIT (ptr);
+ _flockfile (fp);
+ result = __sputc_r (ptr, c, fp);
+ _funlockfile (fp);
+ 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 (c, fp);
+ result = __sputc_r (_REENT, c, fp);
_funlockfile (fp);
return result;
+#else
+ return _putc_r (_REENT, c, fp);
+#endif
}
+#endif /* !_REENT_ONLY */
+
INDEX
putc_unlocked
+INDEX
+ _putc_unlocked_r
POSIX_SYNOPSIS
#include <stdio.h>
int putc_unlocked(int <[ch]>, FILE *<[fp]>);
+ #include <stdio.h>
+ int _putc_unlocked_r(struct _reent *<[ptr]>, int <[ch]>, FILE *<[fp]>);
+
DESCRIPTION
<<putc_unlocked>> is a non-thread-safe version of <<putc>> declared in
<<stdio.h>>. <<putc_unlocked>> may only safely be used within a scope
ftrylockfile() functions. If threads are disabled, then
<<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
See <<putc>>.
#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
_DEFUN(putc_unlocked, (c, fp),
int c _AND
{
/* CHECK_INIT is (eventually) called by __swbuf. */
- return __sputc (c, fp);
+ return __sputc_r (_REENT, c, fp);
}
+#endif /* !_REENT_ONLY */
int c)
{
_REENT_SMALL_CHECK_INIT (ptr);
- return putc (c, _stdout_r (ptr));
+ return _putc_r (ptr, c, _stdout_r (ptr));
}
#ifndef _REENT_ONLY
_DEFUN(putchar, (c),
int c)
{
- /* CHECK_INIT is (eventually) called by __swbuf. */
-
- return _putchar_r (_REENT, c);
+ _REENT_SMALL_CHECK_INIT (_REENT);
+ return _putc_r (_REENT, c, _stdout_r (_REENT));
}
#endif
uio.uio_iovcnt = 2;
_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
#include <_ansi.h>
#include <stdio.h>
#include <stdlib.h>
+#include <errno.h>
#include "local.h"
static int
*/
int
-_DEFUN(__srefill, (fp),
+_DEFUN(__srefill_r, (ptr, fp),
+ struct _reent * ptr _AND
register FILE * fp)
{
/* make sure stdio is set up */
if ((fp->_flags & __SRD) == 0)
{
if ((fp->_flags & __SRW) == 0)
- return EOF;
+ {
+ ptr->_errno = EBADF;
+ fp->_flags |= __SERR;
+ return EOF;
+ }
/* switch to reading */
if (fp->_flags & __SWR)
{
#include <_ansi.h>
#include <stdio.h>
+#include <errno.h>
#include "local.h"
/*
*/
int
-_DEFUN(__srget, (fp),
+_DEFUN(__srget_r, (ptr, fp),
+ struct _reent *ptr _AND
register FILE *fp)
{
- if (__srefill (fp) == 0)
+ if (__srefill_r (ptr, fp) == 0)
{
fp->_r--;
return *fp->_p++;
* then reset it so that it can be reused.
*/
static int
-_DEFUN(__sprint, (fp, uio),
+_DEFUN(__sprint_r, (ptr, fp, uio),
+ struct _reent *ptr _AND
FILE *fp _AND
register struct __suio *uio)
{
uio->uio_iovcnt = 0;
return (0);
}
- err = __sfvwrite(fp, uio);
+ err = __sfvwrite_r(ptr, fp, uio);
uio->uio_resid = 0;
uio->uio_iovcnt = 0;
return (err);
uio.uio_resid += (len); \
iovp++; \
if (++uio.uio_iovcnt >= NIOV) { \
- if (__sprint(fp, &uio)) \
+ if (__sprint_r(data, fp, &uio)) \
goto error; \
iovp = iov; \
} \
} \
}
#define FLUSH() { \
- if (uio.uio_resid && __sprint(fp, &uio)) \
+ if (uio.uio_resid && __sprint_r(data, fp, &uio)) \
goto error; \
uio.uio_iovcnt = 0; \
iovp = iov; \
* vfscanf
*/
-#define BufferEmpty (fp->_r <= 0 && __srefill(fp))
+#define BufferEmpty (fp->_r <= 0 && __srefill_r(rptr, fp))
#ifndef _REENT_ONLY
if (--fp->_r > 0)
fp->_p++;
else
- if (__srefill (fp))
+ if (__srefill_r (rptr, fp))
goto input_failure;
}
/*
sum += n;
width -= n;
fp->_p += n;
- if (__srefill (fp))
+ if (__srefill_r (rptr, fp))
{
if (sum == 0)
goto input_failure;
if (--fp->_r > 0)
fp->_p++;
else
- if (__srefill (fp))
+ if (__srefill_r (rptr, fp))
break; /* EOF */
}
/*
if (--fp->_r > 0)
fp->_p++;
else
- if (__srefill (fp))
+ if (__srefill_r (rptr, fp))
break; /* EOF */
}
if (zeroes)
#include <_ansi.h>
#include <stdio.h>
+#include <errno.h>
#include "local.h"
#include "fvwrite.h"
*/
int
-_DEFUN(__swbuf, (c, fp),
+_DEFUN(__swbuf_r, (ptr, c, fp),
+ struct _reent *ptr _AND
register int c _AND
register FILE *fp)
{
/* Ensure stdio has been initialized. */
- CHECK_INIT (_REENT);
+ CHECK_INIT (ptr);
/*
* In case we cannot write, or longjmp takes us out early,
fp->_w = fp->_lbfsize;
if (cantwrite (fp))
- return EOF;
+ {
+ fp->_flags |= __SERR;
+ ptr->_errno = EBADF;
+ return EOF;
+ }
c = (unsigned char) c;
/*
n = target - curoff;
if (n)
{
- if (__srefill (fp) || fp->_r < n)
+ if (__srefill_r (ptr, fp) || fp->_r < n)
goto dumb;
fp->_p += n;
fp->_r -= n;
+#if 0 /* We don't need this file because math.h defines these values. */
+
/* `HUGE_VAL' constants for ix86 (where it is infinity).
Used by <stdlib.h> and <math.h> functions for overflow.
Copyright (C) 1992, 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
# endif /* GCC 2.95 */
+#endif /* if 0 */