summaryrefslogtreecommitdiffstats
path: root/newlib/libc/stdio/freopen.c
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2007-06-04 18:10:17 +0000
committerEric Blake <eblake@redhat.com>2007-06-04 18:10:17 +0000
commit17c61d6a2c4868260c1ef3043e03f86de14f6a08 (patch)
treec795768b8f7d0fa0048f5bd77f6dad9c5ce069e1 /newlib/libc/stdio/freopen.c
parent6a3b4eb69a7d2b1e1c19a8baef42ce6dc3d61a86 (diff)
downloadcygnal-17c61d6a2c4868260c1ef3043e03f86de14f6a08.tar.gz
cygnal-17c61d6a2c4868260c1ef3043e03f86de14f6a08.tar.bz2
cygnal-17c61d6a2c4868260c1ef3043e03f86de14f6a08.zip
Implement funopen, fopencookie.
* libc/include/sys/reent.h (struct __sFILE, struct __sFILE64): Switch to reentrant callbacks. * libc/include/stdio.h (funopen): Fix declaration. (fopencookie): Declare. * libc/stdio/local.h (__sread, __swrite, __sseek, __sclose) (__sseek64, __swrite64): Fix prototypes. [__SCLE]: Pull in setmode declaration. * libc/stdio/stdio.c (__sread, __swrite, __sseek, __sclose): Fix reentrancy. * libc/stdio64/stdio64.c (__sseek64_r, __swrite64_r): Delete. (__sseek64, __swrite64): Fix reentrancy. * libc/stdio/fseek.c (_fseek_r): Account for overflow, and fix reentrancy. * libc/stdio/ftell.c (_ftell_r): Likewise. * libc/stdio/flags.c (__sflags): Don't lose __SAPP on "a+". * libc/stdio/fclose.c (_fclose_r): Fix reentrancy. * libc/stdio/freopen.c (_freopen_r): Likewise. * libc/stdio/fvwrite.c (__sfvwrite_r): Likewise. * libc/stdio/refill.c (__srefill_r): Likewise. * libc/stdio/siscanf.c (eofread): Likewise. * libc/stdio/sscanf.c (eofread): Likewise. * libc/stdio/vsiscanf.c (eofread1): Likewise. * libc/stdio/vsscanf.c (eofread1): Likewise. * libc/stdio64/freopen64.c (_freopen64_r): Likewise. * libc/stdio64/fseeko64.c (_fseeko64_r): Likewise. * libc/stdio64/ftello64.c (_ftello64_r): Likewise. * libc/stdio/fflush.c (fflush): Improve reentrancy, although more could be fixed. * libc/stdio/fopencookie.c (_fopencookie_r, fopencookie): New file. * libc/stdio/funopen.c (_funopen_r, funopen): New file. * libc/stdio/Makefile.am (ELIX_4_SOURCES, CHEWOUT_FILES): Build new files. * libc/stdio/Makefile.in: Regenerate.
Diffstat (limited to 'newlib/libc/stdio/freopen.c')
-rw-r--r--newlib/libc/stdio/freopen.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/newlib/libc/stdio/freopen.c b/newlib/libc/stdio/freopen.c
index 6d885db2c..f6d658c63 100644
--- a/newlib/libc/stdio/freopen.c
+++ b/newlib/libc/stdio/freopen.c
@@ -28,8 +28,8 @@ ANSI_SYNOPSIS
#include <stdio.h>
FILE *freopen(const char *<[file]>, const char *<[mode]>,
FILE *<[fp]>);
- FILE *_freopen_r(struct _reent *<[ptr]>, const char *<[file]>,
- const char *<[mode]>, FILE *<[fp]>);
+ FILE *_freopen_r(struct _reent *<[ptr]>, const char *<[file]>,
+ const char *<[mode]>, FILE *<[fp]>);
TRAD_SYNOPSIS
#include <stdio.h>
@@ -89,8 +89,8 @@ Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
FILE *
_DEFUN(_freopen_r, (ptr, file, mode, fp),
struct _reent *ptr _AND
- _CONST char *file _AND
- _CONST char *mode _AND
+ const char *file _AND
+ const char *mode _AND
register FILE *fp)
{
register int f;
@@ -106,7 +106,7 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
if ((flags = __sflags (ptr, mode, &oflags)) == 0)
{
_funlockfile (fp);
- _CAST_VOID _fclose_r (ptr, fp);
+ _fclose_r (ptr, fp);
__sfp_lock_release ();
return NULL;
}
@@ -124,13 +124,13 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
else
{
if (fp->_flags & __SWR)
- _CAST_VOID fflush (fp);
+ fflush (fp);
/*
* If close is NULL, closing is a no-op, hence pointless.
* If file is NULL, the file should not be closed.
*/
if (fp->_close != NULL && file != NULL)
- _CAST_VOID (*fp->_close) (fp->_cookie);
+ fp->_close (ptr, fp->_cookie);
}
/*
@@ -154,10 +154,10 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
*/
f = fp->_file;
if ((oldflags = _fcntl_r (ptr, f, F_GETFL, 0)) == -1
- || ! ((oldflags & O_ACCMODE) == O_RDWR
- || ((oldflags ^ oflags) & O_ACCMODE) == 0)
- || _fcntl_r (ptr, f, F_SETFL, oflags) == -1)
- f = -1;
+ || ! ((oldflags & O_ACCMODE) == O_RDWR
+ || ((oldflags ^ oflags) & O_ACCMODE) == 0)
+ || _fcntl_r (ptr, f, F_SETFL, oflags) == -1)
+ f = -1;
#else
/* We cannot modify without fcntl support. */
f = -1;
@@ -168,16 +168,16 @@ _DEFUN(_freopen_r, (ptr, file, mode, fp),
* F_SETFL doesn't change textmode. Don't mess with modes of ttys.
*/
if (0 <= f && ! isatty (f)
- && setmode (f, oflags & (O_BINARY | O_TEXT)) == -1)
- f = -1;
+ && setmode (f, oflags & (O_BINARY | O_TEXT)) == -1)
+ f = -1;
#endif
if (f < 0)
- {
- e = EBADF;
- if (fp->_close != NULL)
- _CAST_VOID (*fp->_close) (fp->_cookie);
- }
+ {
+ e = EBADF;
+ if (fp->_close != NULL)
+ fp->_close (ptr, fp->_cookie);
+ }
}
/*