diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2006-06-15 00:49:11 +0400 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2006-06-15 00:49:11 +0400 |
commit | 4dc0c0c4e5f76c22b39976dd381e04699ab0f09d (patch) | |
tree | c3ac4ca00812cff8cbdaf27f698768a73f922ffb /newlib/libc | |
parent | 1b9cba59c38702b6bcdec116591d3c7191ea7ad7 (diff) |
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>.
Diffstat (limited to 'newlib/libc')
26 files changed, 428 insertions, 92 deletions
diff --git a/newlib/libc/include/stdio.h b/newlib/libc/include/stdio.h index 5fc2f4bfd..fb132f6af 100644 --- a/newlib/libc/include/stdio.h +++ b/newlib/libc/include/stdio.h @@ -293,11 +293,19 @@ int _EXFUN(_fcloseall_r, (struct _reent *)); 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 *, ...)); @@ -305,6 +313,9 @@ int _EXFUN(_mkstemp_r, (struct _reent *, 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 *)); @@ -366,8 +377,8 @@ FILE * _EXFUN(_tmpfile64_r, (struct _reent *)); * 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. @@ -388,15 +399,15 @@ FILE *_EXFUN(funopen,(const _PTR _cookie, * 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 @@ -405,37 +416,37 @@ static __inline__ int __sgetc(FILE *__p) 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 @@ -454,8 +465,8 @@ static __inline int __sputc(int _c, FILE *_p) { #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__ */ @@ -465,7 +476,7 @@ static __inline int __sputc(int _c, FILE *_p) { #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__ diff --git a/newlib/libc/stdio/fgetc.c b/newlib/libc/stdio/fgetc.c index 020b2da3a..1802acf7e 100644 --- a/newlib/libc/stdio/fgetc.c +++ b/newlib/libc/stdio/fgetc.c @@ -21,16 +21,26 @@ FUNCTION 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 @@ -38,6 +48,10 @@ current position indicator. 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 @@ -58,13 +72,35 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, #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 */ + diff --git a/newlib/libc/stdio/fgets.c b/newlib/libc/stdio/fgets.c index f5dde4903..741618705 100644 --- a/newlib/libc/stdio/fgets.c +++ b/newlib/libc/stdio/fgets.c @@ -21,11 +21,16 @@ FUNCTION 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]>) @@ -33,11 +38,21 @@ TRAD_SYNOPSIS 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 @@ -66,7 +81,8 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, */ 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) @@ -80,7 +96,7 @@ _DEFUN(fgets, (buf, n, fp), s = buf; - CHECK_INIT(_REENT); + CHECK_INIT(ptr); _flockfile (fp); #ifdef __SCLE @@ -88,7 +104,7 @@ _DEFUN(fgets, (buf, n, fp), { 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') @@ -113,7 +129,7 @@ _DEFUN(fgets, (buf, n, fp), */ if ((len = fp->_r) <= 0) { - if (__srefill (fp)) + if (__srefill_r (ptr, fp)) { /* EOF: stop with partial or no line */ if (s == buf) @@ -156,3 +172,16 @@ _DEFUN(fgets, (buf, n, fp), _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 */ diff --git a/newlib/libc/stdio/fputc.c b/newlib/libc/stdio/fputc.c index 422f6753a..520fc0250 100644 --- a/newlib/libc/stdio/fputc.c +++ b/newlib/libc/stdio/fputc.c @@ -21,17 +21,28 @@ FUNCTION 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 @@ -45,6 +56,9 @@ oadvances by one. 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 @@ -62,14 +76,34 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, #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 */ diff --git a/newlib/libc/stdio/fputs.c b/newlib/libc/stdio/fputs.c index 8d02107df..93537b9e4 100644 --- a/newlib/libc/stdio/fputs.c +++ b/newlib/libc/stdio/fputs.c @@ -21,21 +21,35 @@ FUNCTION 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>>. @@ -58,7 +72,8 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, */ int -_DEFUN(fputs, (s, fp), +_DEFUN(_fputs_r, (ptr, s, fp), + struct _reent * ptr _AND char _CONST * s _AND FILE * fp) { @@ -71,10 +86,20 @@ _DEFUN(fputs, (s, 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 */ diff --git a/newlib/libc/stdio/fread.c b/newlib/libc/stdio/fread.c index 1354c04ba..8df577006 100644 --- a/newlib/libc/stdio/fread.c +++ b/newlib/libc/stdio/fread.c @@ -21,12 +21,19 @@ FUNCTION 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]>) @@ -35,6 +42,14 @@ TRAD_SYNOPSIS 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, @@ -44,6 +59,9 @@ starting at <[buf]>. <<fread>> may copy fewer elements than <<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. @@ -63,7 +81,8 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, #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 @@ -86,7 +105,7 @@ _DEFUN(crlf, (fp, buf, count, eof), { if (*s == '\r') { - int c = __sgetc_raw (fp); + int c = __sgetc_raw_r (ptr, fp); if (c == '\n') *s = '\n'; else @@ -98,7 +117,7 @@ _DEFUN(crlf, (fp, buf, count, eof), while (d < e) { - r = getc (fp); + r = _getc_r (ptr, fp); if (r == EOF) return count - (e-d); *d++ = r; @@ -111,7 +130,8 @@ _DEFUN(crlf, (fp, buf, count, eof), #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 @@ -125,7 +145,7 @@ _DEFUN(fread, (buf, size, count, fp), if ((resid = count * size) == 0) return 0; - CHECK_INIT(_REENT); + CHECK_INIT(ptr); _flockfile (fp); if (fp->_r < 0) @@ -162,7 +182,7 @@ _DEFUN(fread, (buf, size, count, fp), 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; @@ -194,7 +214,7 @@ _DEFUN(fread, (buf, size, count, fp), /* 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 @@ -224,3 +244,15 @@ _DEFUN(fread, (buf, size, count, fp), _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 diff --git a/newlib/libc/stdio/fseek.c b/newlib/libc/stdio/fseek.c index 8b189ba17..09edc42d1 100644 --- a/newlib/libc/stdio/fseek.c +++ b/newlib/libc/stdio/fseek.c @@ -333,7 +333,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence), 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; diff --git a/newlib/libc/stdio/fvwrite.c b/newlib/libc/stdio/fvwrite.c index f036d7483..1cb6e0d1e 100644 --- a/newlib/libc/stdio/fvwrite.c +++ b/newlib/libc/stdio/fvwrite.c @@ -20,6 +20,7 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> +#include <errno.h> #include "local.h" #include "fvwrite.h" @@ -43,7 +44,8 @@ */ int -_DEFUN(__sfvwrite, (fp, uio), +_DEFUN(__sfvwrite_r, (ptr, fp, uio), + struct _reent *ptr _AND register FILE *fp _AND register struct __suio *uio) { @@ -59,7 +61,11 @@ _DEFUN(__sfvwrite, (fp, 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; diff --git a/newlib/libc/stdio/fvwrite.h b/newlib/libc/stdio/fvwrite.h index f27abdf81..901b56058 100644 --- a/newlib/libc/stdio/fvwrite.h +++ b/newlib/libc/stdio/fvwrite.h @@ -19,7 +19,7 @@ #include <_ansi.h> /* - * I/O descriptors for __sfvwrite(). + * I/O descriptors for __sfvwrite_r(). */ struct __siov { _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 *)); diff --git a/newlib/libc/stdio/fwrite.c b/newlib/libc/stdio/fwrite.c index 663fff62c..8a2159c4a 100644 --- a/newlib/libc/stdio/fwrite.c +++ b/newlib/libc/stdio/fwrite.c @@ -21,12 +21,18 @@ FUNCTION 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]>) @@ -35,6 +41,14 @@ TRAD_SYNOPSIS 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 @@ -44,6 +58,9 @@ stream identified by <[fp]>. <<fwrite>> may copy fewer elements than <<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 @@ -78,7 +95,8 @@ static char sccsid[] = "%W% (Berkeley) %G%"; */ 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 @@ -94,15 +112,15 @@ _DEFUN(fwrite, (buf, size, count, fp), 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; @@ -110,3 +128,15 @@ _DEFUN(fwrite, (buf, size, count, fp), _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 diff --git a/newlib/libc/stdio/getc.c b/newlib/libc/stdio/getc.c index 9628a8740..c02fe6b3d 100644 --- a/newlib/libc/stdio/getc.c +++ b/newlib/libc/stdio/getc.c @@ -21,16 +21,26 @@ FUNCTION 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 @@ -39,6 +49,9 @@ current position indicator. 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 @@ -73,13 +86,30 @@ static char sccsid[] = "%W% (Berkeley) %G%"; #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 */ diff --git a/newlib/libc/stdio/getc_u.c b/newlib/libc/stdio/getc_u.c index 9c05fa6f5..7d7adde60 100644 --- a/newlib/libc/stdio/getc_u.c +++ b/newlib/libc/stdio/getc_u.c @@ -21,11 +21,16 @@ FUNCTION 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 @@ -36,6 +41,10 @@ object, as is the case after a successful call to the flockfile() or 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>>. @@ -60,10 +69,22 @@ static char sccsid[] = "%W% (Berkeley) %G%"; #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 */ diff --git a/newlib/libc/stdio/getchar.c b/newlib/libc/stdio/getchar.c index 19301c113..da2f5dfaf 100644 --- a/newlib/libc/stdio/getchar.c +++ b/newlib/libc/stdio/getchar.c @@ -79,11 +79,11 @@ static char sccsid[] = "%W% (Berkeley) %G%"; #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 @@ -91,9 +91,9 @@ _DEFUN(_getchar_r, (f), 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 diff --git a/newlib/libc/stdio/getchar_u.c b/newlib/libc/stdio/getchar_u.c index be566ea26..ce4014519 100644 --- a/newlib/libc/stdio/getchar_u.c +++ b/newlib/libc/stdio/getchar_u.c @@ -21,11 +21,16 @@ FUNCTION 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 @@ -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, 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>>. @@ -61,10 +70,10 @@ static char sccsid[] = "%W% (Berkeley) %G%"; #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 @@ -72,9 +81,9 @@ _DEFUN(_getchar_unlocked_r, (f), 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 diff --git a/newlib/libc/stdio/local.h b/newlib/libc/stdio/local.h index f7093b697..301abce33 100644 --- a/newlib/libc/stdio/local.h +++ b/newlib/libc/stdio/local.h @@ -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 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)); @@ -45,7 +45,6 @@ extern _VOID _EXFUN(__smakebuf,(FILE *)); 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. */ diff --git a/newlib/libc/stdio/putc.c b/newlib/libc/stdio/putc.c index 097323417..b3008e287 100644 --- a/newlib/libc/stdio/putc.c +++ b/newlib/libc/stdio/putc.c @@ -21,17 +21,28 @@ FUNCTION 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 @@ -45,6 +56,9 @@ advances by one. 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 @@ -76,14 +90,35 @@ static char sccsid[] = "%W% (Berkeley) %G%"; #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 */ + diff --git a/newlib/libc/stdio/putc_u.c b/newlib/libc/stdio/putc_u.c index aee11f4e7..9960654d7 100644 --- a/newlib/libc/stdio/putc_u.c +++ b/newlib/libc/stdio/putc_u.c @@ -21,11 +21,16 @@ FUNCTION 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 @@ -36,6 +41,10 @@ object, as is the case after a successful call to the flockfile() or 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>>. @@ -61,11 +70,24 @@ static char sccsid[] = "%W% (Berkeley) %G%"; #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 register FILE *fp) { /* CHECK_INIT is (eventually) called by __swbuf. */ - return __sputc (c, fp); + return __sputc_r (_REENT, c, fp); } +#endif /* !_REENT_ONLY */ diff --git a/newlib/libc/stdio/putchar.c b/newlib/libc/stdio/putchar.c index e1d748ae2..06bcbb46e 100644 --- a/newlib/libc/stdio/putchar.c +++ b/newlib/libc/stdio/putchar.c @@ -81,7 +81,7 @@ _DEFUN(_putchar_r, (ptr, c), int c) { _REENT_SMALL_CHECK_INIT (ptr); - return putc (c, _stdout_r (ptr)); + return _putc_r (ptr, c, _stdout_r (ptr)); } #ifndef _REENT_ONLY @@ -90,9 +90,8 @@ int _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 diff --git a/newlib/libc/stdio/puts.c b/newlib/libc/stdio/puts.c index bf32d0401..e6c4d2e14 100644 --- a/newlib/libc/stdio/puts.c +++ b/newlib/libc/stdio/puts.c @@ -91,7 +91,7 @@ _DEFUN(_puts_r, (ptr, s), 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 diff --git a/newlib/libc/stdio/refill.c b/newlib/libc/stdio/refill.c index 639ce6e24..047387e79 100644 --- a/newlib/libc/stdio/refill.c +++ b/newlib/libc/stdio/refill.c @@ -19,6 +19,7 @@ #include <_ansi.h> #include <stdio.h> #include <stdlib.h> +#include <errno.h> #include "local.h" static int @@ -36,7 +37,8 @@ _DEFUN(lflush, (fp), */ int -_DEFUN(__srefill, (fp), +_DEFUN(__srefill_r, (ptr, fp), + struct _reent * ptr _AND register FILE * fp) { /* make sure stdio is set up */ @@ -55,7 +57,11 @@ _DEFUN(__srefill, (fp), 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) { diff --git a/newlib/libc/stdio/rget.c b/newlib/libc/stdio/rget.c index ee4e49ec9..1c0bc474c 100644 --- a/newlib/libc/stdio/rget.c +++ b/newlib/libc/stdio/rget.c @@ -22,6 +22,7 @@ static char sccsid[] = "%W% (Berkeley) %G%"; #include <_ansi.h> #include <stdio.h> +#include <errno.h> #include "local.h" /* @@ -31,10 +32,11 @@ static char sccsid[] = "%W% (Berkeley) %G%"; */ 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++; diff --git a/newlib/libc/stdio/vfprintf.c b/newlib/libc/stdio/vfprintf.c index a8c1f9bca..370ffe0e5 100644 --- a/newlib/libc/stdio/vfprintf.c +++ b/newlib/libc/stdio/vfprintf.c @@ -212,7 +212,8 @@ static char *rcsid = "$Id$"; * 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) { @@ -222,7 +223,7 @@ _DEFUN(__sprint, (fp, 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); @@ -469,7 +470,7 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap), uio.uio_resid += (len); \ iovp++; \ if (++uio.uio_iovcnt >= NIOV) { \ - if (__sprint(fp, &uio)) \ + if (__sprint_r(data, fp, &uio)) \ goto error; \ iovp = iov; \ } \ @@ -484,7 +485,7 @@ _DEFUN(_VFPRINTF_R, (data, fp, fmt0, ap), } \ } #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; \ diff --git a/newlib/libc/stdio/vfscanf.c b/newlib/libc/stdio/vfscanf.c index 4788938c9..7bf0aaf9a 100644 --- a/newlib/libc/stdio/vfscanf.c +++ b/newlib/libc/stdio/vfscanf.c @@ -221,7 +221,7 @@ typedef unsigned long long u_long_long; * vfscanf */ -#define BufferEmpty (fp->_r <= 0 && __srefill(fp)) +#define BufferEmpty (fp->_r <= 0 && __srefill_r(rptr, fp)) #ifndef _REENT_ONLY @@ -547,7 +547,7 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap), if (--fp->_r > 0) fp->_p++; else - if (__srefill (fp)) + if (__srefill_r (rptr, fp)) goto input_failure; } /* @@ -615,7 +615,7 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap), sum += n; width -= n; fp->_p += n; - if (__srefill (fp)) + if (__srefill_r (rptr, fp)) { if (sum == 0) goto input_failure; @@ -910,7 +910,7 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap), if (--fp->_r > 0) fp->_p++; else - if (__srefill (fp)) + if (__srefill_r (rptr, fp)) break; /* EOF */ } /* @@ -1107,7 +1107,7 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap), if (--fp->_r > 0) fp->_p++; else - if (__srefill (fp)) + if (__srefill_r (rptr, fp)) break; /* EOF */ } if (zeroes) diff --git a/newlib/libc/stdio/wbuf.c b/newlib/libc/stdio/wbuf.c index e7ddb4913..95d0e4d71 100644 --- a/newlib/libc/stdio/wbuf.c +++ b/newlib/libc/stdio/wbuf.c @@ -22,6 +22,7 @@ static char sccsid[] = "%W% (Berkeley) %G%"; #include <_ansi.h> #include <stdio.h> +#include <errno.h> #include "local.h" #include "fvwrite.h" @@ -32,7 +33,8 @@ static char sccsid[] = "%W% (Berkeley) %G%"; */ int -_DEFUN(__swbuf, (c, fp), +_DEFUN(__swbuf_r, (ptr, c, fp), + struct _reent *ptr _AND register int c _AND register FILE *fp) { @@ -40,7 +42,7 @@ _DEFUN(__swbuf, (c, fp), /* Ensure stdio has been initialized. */ - CHECK_INIT (_REENT); + CHECK_INIT (ptr); /* * In case we cannot write, or longjmp takes us out early, @@ -52,7 +54,11 @@ _DEFUN(__swbuf, (c, fp), fp->_w = fp->_lbfsize; if (cantwrite (fp)) - return EOF; + { + fp->_flags |= __SERR; + ptr->_errno = EBADF; + return EOF; + } c = (unsigned char) c; /* diff --git a/newlib/libc/stdio64/fseeko64.c b/newlib/libc/stdio64/fseeko64.c index edd764009..971bd4d08 100644 --- a/newlib/libc/stdio64/fseeko64.c +++ b/newlib/libc/stdio64/fseeko64.c @@ -309,7 +309,7 @@ _DEFUN (_fseeko64_r, (ptr, fp, offset, whence), 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; diff --git a/newlib/libc/sys/linux/machine/i386/huge_val.h b/newlib/libc/sys/linux/machine/i386/huge_val.h index 171517710..8ead007d7 100644 --- a/newlib/libc/sys/linux/machine/i386/huge_val.h +++ b/newlib/libc/sys/linux/machine/i386/huge_val.h @@ -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). Used by <stdlib.h> and <math.h> functions for overflow. 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 /* if 0 */ |