2002-07-18 07:25:44 +08:00
|
|
|
/* No user fns here. Pesch 15apr92. */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1990 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that the above copyright notice and this paragraph are
|
|
|
|
* duplicated in all such forms and that any documentation,
|
|
|
|
* advertising materials, and other materials related to such
|
|
|
|
* distribution and use acknowledge that the software was developed
|
|
|
|
* by the University of California, Berkeley. The name of the
|
|
|
|
* University may not be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <sys/unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "local.h"
|
|
|
|
|
|
|
|
#ifdef __LARGE64_FILES
|
|
|
|
_fpos64_t
|
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.
2007-06-05 02:10:17 +08:00
|
|
|
_DEFUN(__sseek64, (ptr, cookie, offset, whence),
|
|
|
|
struct _reent *ptr _AND
|
|
|
|
void *cookie _AND
|
|
|
|
_fpos64_t offset _AND
|
|
|
|
int whence)
|
2002-07-18 07:25:44 +08:00
|
|
|
{
|
|
|
|
register FILE *fp = (FILE *) cookie;
|
|
|
|
register _off64_t ret;
|
|
|
|
|
2003-08-23 02:52:25 +08:00
|
|
|
ret = _lseek64_r (ptr, fp->_file, (_off64_t) offset, whence);
|
2002-07-18 07:25:44 +08:00
|
|
|
if (ret == (_fpos64_t)-1L)
|
|
|
|
fp->_flags &= ~__SOFF;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fp->_flags |= __SOFF;
|
|
|
|
fp->_offset = ret;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
_READ_WRITE_RETURN_TYPE
|
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.
2007-06-05 02:10:17 +08:00
|
|
|
_DEFUN(__swrite64, (ptr, cookie, buf, n),
|
|
|
|
struct _reent *ptr _AND
|
|
|
|
void *cookie _AND
|
|
|
|
char const *buf _AND
|
|
|
|
int n)
|
2002-07-18 07:25:44 +08:00
|
|
|
{
|
|
|
|
register FILE *fp = (FILE *) cookie;
|
|
|
|
int w;
|
|
|
|
#ifdef __SCLE
|
|
|
|
int oldmode=0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (fp->_flags & __SAPP)
|
2003-08-23 02:52:25 +08:00
|
|
|
(void) _lseek64_r (ptr, fp->_file, (_off64_t)0, SEEK_END);
|
2002-07-18 07:25:44 +08:00
|
|
|
fp->_flags &= ~__SOFF; /* in case O_APPEND mode is set */
|
|
|
|
|
|
|
|
#ifdef __SCLE
|
|
|
|
if (fp->_flags & __SCLE)
|
|
|
|
oldmode = setmode(fp->_file, O_BINARY);
|
|
|
|
#endif
|
|
|
|
|
2003-08-23 02:52:25 +08:00
|
|
|
w = _write_r (ptr, fp->_file, buf, n);
|
2002-07-18 07:25:44 +08:00
|
|
|
|
|
|
|
#ifdef __SCLE
|
|
|
|
if (oldmode)
|
|
|
|
setmode(fp->_file, oldmode);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
2003-08-23 02:52:25 +08:00
|
|
|
|
2002-07-18 07:25:44 +08:00
|
|
|
#endif /* __LARGE64_FILES */
|