diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2003-08-22 22:52:25 +0400 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2003-08-22 22:52:25 +0400 |
commit | 9fc9e1c916af8d91539ace77cb123b4fa99e0d37 (patch) | |
tree | cb8b0274943fdc015072f18c9b230cb91268d36e /newlib/libc/stdio64 | |
parent | c5a12ca3b96fad61372e57215b401e2b4ee3f972 (diff) |
2003-08-22 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/sys/reent.h: Add _GLOBAL_REENT macro.
* libc/stdio: Globally remove/replace all references to fp->_data.
Replace with _REENT or _GLOBAL_REENT where appropriate.
* libc/stdio/asprintf.c: Ditto.
* libc/stdio/fclose.c: Ditto.
* libc/stdio/fvwrite.c: Ditto.
* libc/stdio/makebuf.c: Ditto.
* libc/stdio/refill.c: Ditto.
* libc/stdio/local.h: Ditto.
* libc/stdio/setvbuf.c: Ditto.
* libc/stdio/sscanf.c: Ditto.
* libc/stdio/stdio.c: Ditto.
* libc/stdio/ungetc.c: Ditto.
* libc/stdio/vfscanf.c: Ditto.
* libc/stdio/vsscanf.c: Ditto.
* libc/stdio/fopen.c: Ditto. Also use _fseek_r in _fopen_r.
* libc/stdio/vasprintf.c: Ditto. Also call _vfprintf_r directly.
* libc/stdio/vsnprintf.c: Ditto.
* libc/stdio/vsprintf.c: Ditto.
* libc/stdio/fcloseall.c(fcloseall): Use _GLOBAL_REENT macro
instead of _REENT to walk file list.
* libc/stdio/fflush.c: Ditto.
* libc/stdio/fgetpos.c: Add reentrant version and have regular
version call reentrant version with _REENT argument.
* libc/stdio/fsetpos.c: Ditto.
* libc/stdio/fseek.c: Ditto.
* libc/stdio/fseeko.c: Ditto.
* libc/stdio/ftell.c: Ditto.
* libc/stdio/ftello.c: Ditto.
* libc/stdio/freopen.c: Ditto.
* libc/stdio/findfp.c: Use _GLOBAL_REENT pointer when adding
new files to chain. Also use _GLOBAL_REENT pointer for
cleaning up.
* libc/stdio/fiprintf.c: Reformatted to minimize duplicate code.
* libc/stdio/siprintf.c: Ditto.
* libc/stdio/iprintf.c: Ditto.
* libc/stdio/fprintf.c: Ditto.
* libc/stdio/printf.c: Ditto.
* libc/stdio/snprintf.c: Call _vfprintf_r directly.
* libc/stdio/sprintf.c: Ditto.
* libc/stdio/vprintf.c: Ditto. Also add _REENT_ONLY check.
* libc/stdio/rewind.c: Call _fseek_r directly.
* libc/stdio/tmpfile.c: Call _fopen_r and _remove_r directly.
* libc/stdio/vfprintf.c (_VFPRINTF_R): Change _r routines to use
data pointer.
(get_arg): Add extra struct _reent pointer argument.
* libc/stdio64/fgetpos64.c: Add _r versions, remove any reference
to fp->_data.
* libc/stdio64/fopen64.c: Ditto.
* libc/stdio64/freopen64.c: Ditto.
* libc/stdio64/fsetpos64.c: Ditto.
* libc/stdio64/ftello64.c: Ditto.
* libc/stdio64/local64.h: Ditto.
* libc/stdio64/stdio64.c: Ditto.
* libc/stdio64/fseeko64.c: Ditto plus use _fstat_r instead of
_fstat64_r for the meantime.
Diffstat (limited to 'newlib/libc/stdio64')
-rw-r--r-- | newlib/libc/stdio64/fgetpos64.c | 25 | ||||
-rw-r--r-- | newlib/libc/stdio64/fopen64.c | 4 | ||||
-rw-r--r-- | newlib/libc/stdio64/freopen64.c | 28 | ||||
-rw-r--r-- | newlib/libc/stdio64/fseeko64.c | 41 | ||||
-rw-r--r-- | newlib/libc/stdio64/fsetpos64.c | 26 | ||||
-rw-r--r-- | newlib/libc/stdio64/ftello64.c | 23 | ||||
-rw-r--r-- | newlib/libc/stdio64/local64.h | 3 | ||||
-rw-r--r-- | newlib/libc/stdio64/stdio64.c | 34 |
8 files changed, 160 insertions, 24 deletions
diff --git a/newlib/libc/stdio64/fgetpos64.c b/newlib/libc/stdio64/fgetpos64.c index 3a0f0d910..5f8c1c3ab 100644 --- a/newlib/libc/stdio64/fgetpos64.c +++ b/newlib/libc/stdio64/fgetpos64.c @@ -4,10 +4,14 @@ FUNCTION INDEX fgetpos64 +INDEX + _fgetpos64_r ANSI_SYNOPSIS #include <stdio.h> int fgetpos64(FILE *<[fp]>, _fpos64_t *<[pos]>); + int _fgetpos64_r(struct _reent *<[ptr]>, FILE *<[fp]>, + _fpos64_t *<[pos]>); TRAD_SYNOPSIS #include <stdio.h> @@ -15,6 +19,10 @@ TRAD_SYNOPSIS FILE *<[fp]>; _fpos64_t *<[pos]>; + int _fgetpos64_r(<[ptr]>, <[fp]>, <[pos]>) + FILE *<[fp]>; + _fpos64_t *<[pos]>; + DESCRIPTION Objects of type <<FILE>> can have a ``position'' that records how much of the file your program has already read. Many of the <<stdio>> functions @@ -47,12 +55,13 @@ No supporting OS subroutines are required. #ifdef __LARGE64_FILES int -_DEFUN (fgetpos64, (fp, pos), +_DEFUN (_fgetpos64_r, (ptr, fp, pos), + struct _reent * ptr _AND FILE * fp _AND _fpos64_t * pos) { _flockfile(fp); - *pos = (_fpos64_t)ftello64 (fp); + *pos = (_fpos64_t)_ftello64_r (ptr, fp); if (*pos != -1) { @@ -63,4 +72,16 @@ _DEFUN (fgetpos64, (fp, pos), return 1; } +#ifndef _REENT_ONLY + +int +_DEFUN (fgetpos64, (fp, pos), + FILE * fp _AND + _fpos64_t * pos) +{ + return _fgetpos64_r (_REENT, fp, pos); +} + +#endif /* !_REENT_ONLY */ + #endif /* __LARGE64_FILES */ diff --git a/newlib/libc/stdio64/fopen64.c b/newlib/libc/stdio64/fopen64.c index d2ab74c35..3c69820ee 100644 --- a/newlib/libc/stdio64/fopen64.c +++ b/newlib/libc/stdio64/fopen64.c @@ -89,7 +89,7 @@ _DEFUN (_fopen64_r, (ptr, file, mode), if ((fp = __sfp (ptr)) == NULL) return NULL; - if ((f = _open64_r (fp->_data, file, oflags, 0666)) < 0) + if ((f = _open64_r (ptr, file, oflags, 0666)) < 0) { fp->_flags = 0; /* release */ return NULL; @@ -105,7 +105,7 @@ _DEFUN (_fopen64_r, (ptr, file, mode), fp->_close = __sclose; if (fp->_flags & __SAPP) - fseeko64 (fp, 0, SEEK_END); + _fseeko64_r (ptr, fp, 0, SEEK_END); #ifdef __SCLE if (__stextmode (fp->_file)) diff --git a/newlib/libc/stdio64/freopen64.c b/newlib/libc/stdio64/freopen64.c index 1828b0656..6e4586cd9 100644 --- a/newlib/libc/stdio64/freopen64.c +++ b/newlib/libc/stdio64/freopen64.c @@ -21,11 +21,15 @@ FUNCTION INDEX freopen64 +INDEX + _freopen64_r ANSI_SYNOPSIS #include <stdio.h> FILE *freopen64(const char *<[file]>, const char *<[mode]>, FILE *<[fp]>); + FILE *_freopen64_r(struct _reent *<[ptr]>, const char *<[file]>, + const char *<[mode]>, FILE *<[fp]>); TRAD_SYNOPSIS #include <stdio.h> @@ -34,6 +38,12 @@ TRAD_SYNOPSIS char *<[mode]>; FILE *<[fp]>; + FILE *_freopen64_r(<[ptr]>, <[file]>, <[mode]>, <[fp]>) + struct _reent *<[ptr]>; + char *<[file]>; + char *<[mode]>; + FILE *<[fp]>; + DESCRIPTION Use this variant of <<fopen64>> if you wish to specify a particular file descriptor <[fp]> (notably <<stdin>>, <<stdout>>, or <<stderr>>) for @@ -69,19 +79,18 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, #ifdef __LARGE64_FILES FILE * -_DEFUN (freopen64, (file, mode, fp), +_DEFUN (_freopen64_r, (ptr, file, mode, fp), + struct _reent *ptr _AND _CONST char *file _AND _CONST char *mode _AND register FILE *fp) { register int f; int flags, oflags, e; - struct _reent *ptr; _flockfile(fp); CHECK_INIT (fp); - ptr = fp->_data; if ((flags = __sflags (ptr, mode, &oflags)) == 0) { @@ -166,4 +175,17 @@ _DEFUN (freopen64, (file, mode, fp), return fp; } +#ifndef _REENT_ONLY + +FILE * +_DEFUN (freopen64, (file, mode, fp), + _CONST char *file _AND + _CONST char *mode _AND + register FILE *fp) +{ + return _freopen64_r (_REENT, file, mode, fp); +} + +#endif /* !_REENT_ONLY */ + #endif /* __LARGE64_FILES */ diff --git a/newlib/libc/stdio64/fseeko64.c b/newlib/libc/stdio64/fseeko64.c index 3623ba7f9..e88b6c722 100644 --- a/newlib/libc/stdio64/fseeko64.c +++ b/newlib/libc/stdio64/fseeko64.c @@ -21,11 +21,14 @@ FUNCTION INDEX fseeko64 +INDEX + _fseeko64_r ANSI_SYNOPSIS #include <stdio.h> int fseeko64(FILE *<[fp]>, _off64_t <[offset]>, int <[whence]>) - + int _fseeko64_r (struct _reent *<[ptr]>, FILE *<[fp]>, + _off64_t <[offset]>, int <[whence]>) TRAD_SYNOPSIS #include <stdio.h> @@ -34,6 +37,12 @@ TRAD_SYNOPSIS _off64_t <[offset]>; int <[whence]>; + int _fseeko64_r (<[ptr]>, <[fp]>, <[offset]>, <[whence]>) + struct _reent *<[ptr]>; + FILE *<[fp]>; + _off64_t <[offset]>; + int <[whence]>; + DESCRIPTION Objects of type <<FILE>> can have a ``position'' that records how much of the file your program has already read. Many of the <<stdio>> functions @@ -89,15 +98,17 @@ Supporting OS subroutines required: <<close>>, <<fstat64>>, <<isatty>>, */ _off64_t -fseeko64 (fp, offset, whence) - register FILE *fp; - _off64_t offset; - int whence; +_DEFUN (_fseeko64_r, (ptr, fp, offset, whence), + struct _reent *ptr _AND + register FILE *fp _AND + _off64_t offset _AND + int whence) { - struct _reent *ptr; _fpos64_t _EXFUN ((*seekfn), (void *, _fpos64_t, int)); _fpos64_t target, curoff; size_t n; + + /* FIXME: this should be stat64. */ struct stat st; int havepos; @@ -106,7 +117,8 @@ fseeko64 (fp, offset, whence) /* Make sure stdio is set up. */ CHECK_INIT (fp); - ptr = fp->_data; + + curoff = fp->_offset; /* If we've been doing some writing, and we're in append mode then we don't really know where the filepos is. */ @@ -193,7 +205,7 @@ fseeko64 (fp, offset, whence) { if (seekfn != __sseek64 || fp->_file < 0 - || _fstat64_r (ptr, fp->_file, &st) + || _fstat_r (ptr, fp->_file, &st) || (st.st_mode & S_IFMT) != S_IFREG) { fp->_flags |= __SNPT; @@ -328,4 +340,17 @@ dumb: return 0; } +#ifndef _REENT_ONLY + +_off64_t +_DEFUN (fseeko64_r, (fp, offset, whence), + register FILE *fp _AND + _off64_t offset _AND + int whence) +{ + return _fseeko64_r (_REENT, fp, offset, whence); +} + +#endif /* !_REENT_ONLY */ + #endif /* __LARGE64_FILES */ diff --git a/newlib/libc/stdio64/fsetpos64.c b/newlib/libc/stdio64/fsetpos64.c index f0ec64ebf..046990d7a 100644 --- a/newlib/libc/stdio64/fsetpos64.c +++ b/newlib/libc/stdio64/fsetpos64.c @@ -4,10 +4,14 @@ FUNCTION INDEX fsetpos64 +INDEX + _fsetpos64_r ANSI_SYNOPSIS #include <stdio.h> int fsetpos64(FILE *<[fp]>, const _fpos64_t *<[pos]>); + int _fsetpos64_r(struct _reent *<[ptr]>, FILE *<[fp]>, + const _fpos64_t *<[pos]>); TRAD_SYNOPSIS #include <stdio.h> @@ -15,6 +19,11 @@ TRAD_SYNOPSIS FILE *<[fp]>; _fpos64_t *<[pos]>; + int _fsetpos64_r(<[ptr]>, <[fp]>, <[pos]>) + struct _reent *<[ptr]>; + FILE *<[fp]>; + _fpos64_t *<[pos]>; + DESCRIPTION Objects of type <<FILE>> can have a ``position'' that records how much of the file your program has already read. Many of the <<stdio>> functions @@ -43,15 +52,28 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, #ifdef __LARGE64_FILES int -_DEFUN (fsetpos64, (iop, pos), +_DEFUN (_fsetpos64_r, (ptr, iop, pos), + struct _reent *ptr _AND FILE * iop _AND _CONST _fpos64_t * pos) { - int x = fseeko64 (iop, (_off64_t)(*pos), SEEK_SET); + int x = _fseeko64_r (ptr, iop, (_off64_t)(*pos), SEEK_SET); if (x != 0) return 1; return 0; } +#ifndef _REENT_ONLY + +int +_DEFUN (fsetpos64, (iop, pos), + FILE * iop _AND + _CONST _fpos64_t * pos) +{ + return _fsetpos64_r (_REENT, iop, pos); +} + +#endif /* !_REENT_ONLY */ + #endif /* __LARGE64_FILES */ diff --git a/newlib/libc/stdio64/ftello64.c b/newlib/libc/stdio64/ftello64.c index 1ca5b0452..aaf0f023e 100644 --- a/newlib/libc/stdio64/ftello64.c +++ b/newlib/libc/stdio64/ftello64.c @@ -21,16 +21,23 @@ FUNCTION INDEX ftello64 +INDEX + _ftello64_r ANSI_SYNOPSIS #include <stdio.h> _off64_t ftello64(FILE *<[fp]>); + _off64_t _ftello64_r(struct _reent *<[ptr]>, FILE *<[fp]>); TRAD_SYNOPSIS #include <stdio.h> _off64_t ftello64(<[fp]>) FILE *<[fp]>; + _off64_t _ftello64_r(<[ptr]>, <[fp]>) + struct _reent *<[ptr]>; + FILE *<[fp]>; + DESCRIPTION Objects of type <<FILE>> can have a ``position'' that records how much of the file your program has already read. Many of the <<stdio>> functions @@ -78,7 +85,8 @@ static char sccsid[] = "%W% (Berkeley) %G%"; #ifdef __LARGE64_FILES _off64_t -_DEFUN (ftello64, (fp), +_DEFUN (_ftello64_r, (ptr, fp), + struct _reent *ptr _AND register FILE * fp) { _fpos64_t pos; @@ -91,7 +99,7 @@ _DEFUN (ftello64, (fp), if (fp->_seek64 == NULL) { - fp->_data->_errno = ESPIPE; + ptr->_errno = ESPIPE; _funlockfile(fp); return -1L; } @@ -135,4 +143,15 @@ _DEFUN (ftello64, (fp), return pos; } +#ifndef _REENT_ONLY + +_off64_t +_DEFUN (ftello64, (fp), + register FILE * fp) +{ + return _ftello64_r (_REENT, fp); +} + +#endif /* !_REENT_ONLY */ + #endif /* __LARGE64_FILES */ diff --git a/newlib/libc/stdio64/local64.h b/newlib/libc/stdio64/local64.h index 98bea6bc2..b86c95d03 100644 --- a/newlib/libc/stdio64/local64.h +++ b/newlib/libc/stdio64/local64.h @@ -7,7 +7,10 @@ #ifdef __LARGE64_FILES extern _fpos64_t _EXFUN(__sseek64,(void *, _fpos64_t, int)); +extern _fpos64_t _EXFUN(__sseek64_r,(struct _reent *, void *, _fpos64_t, int)); extern _fpos64_t _EXFUN(__sseek64_error,(void *, _fpos64_t, int)); extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64,(void *, char const *, int)); +extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64_r,(struct _reent *, void *, + char const *, int)); #endif diff --git a/newlib/libc/stdio64/stdio64.c b/newlib/libc/stdio64/stdio64.c index 7b9e16480..35967ad99 100644 --- a/newlib/libc/stdio64/stdio64.c +++ b/newlib/libc/stdio64/stdio64.c @@ -26,7 +26,8 @@ #ifdef __LARGE64_FILES _fpos64_t -__sseek64 (cookie, offset, whence) +__sseek64_r (ptr, cookie, offset, whence) + struct _reent *ptr; _PTR cookie; _fpos64_t offset; int whence; @@ -34,7 +35,7 @@ __sseek64 (cookie, offset, whence) register FILE *fp = (FILE *) cookie; register _off64_t ret; - ret = _lseek64_r (fp->_data, fp->_file, (_off64_t) offset, whence); + ret = _lseek64_r (ptr, fp->_file, (_off64_t) offset, whence); if (ret == (_fpos64_t)-1L) fp->_flags &= ~__SOFF; else @@ -46,7 +47,8 @@ __sseek64 (cookie, offset, whence) } _READ_WRITE_RETURN_TYPE -__swrite64 (cookie, buf, n) +__swrite64_r (ptr, cookie, buf, n) + struct _reent *ptr; _PTR cookie; char _CONST *buf; int n; @@ -58,7 +60,7 @@ __swrite64 (cookie, buf, n) #endif if (fp->_flags & __SAPP) - (void) _lseek64_r (fp->_data, fp->_file, (_off64_t)0, SEEK_END); + (void) _lseek64_r (ptr, fp->_file, (_off64_t)0, SEEK_END); fp->_flags &= ~__SOFF; /* in case O_APPEND mode is set */ #ifdef __SCLE @@ -66,7 +68,7 @@ __swrite64 (cookie, buf, n) oldmode = setmode(fp->_file, O_BINARY); #endif - w = _write_r (fp->_data, fp->_file, buf, n); + w = _write_r (ptr, fp->_file, buf, n); #ifdef __SCLE if (oldmode) @@ -75,5 +77,27 @@ __swrite64 (cookie, buf, n) return w; } + +#ifndef _REENT_ONLY +_fpos64_t +__sseek64 (cookie, offset, whence) + _PTR cookie; + _fpos64_t offset; + int whence; +{ + return __sseek64_r (_REENT, cookie, offset, whence); +} + +_READ_WRITE_RETURN_TYPE +__swrite64 (cookie, buf, n) + _PTR cookie; + char _CONST *buf; + int n; +{ + return __swrite64_r (_REENT, cookie, buf, n); +} + +#endif /* !_REENT_ONLY */ + #endif /* __LARGE64_FILES */ |