2000-02-18 03:39:52 +08:00
|
|
|
/*
|
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
|
|
|
* Copyright (c) 1990 The Regents of the University of California.
|
2000-02-18 03:39:52 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
FUNCTION
|
2002-07-05 03:33:54 +08:00
|
|
|
<<fseek>>, <<fseeko>>---set file position
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
INDEX
|
|
|
|
fseek
|
2002-07-05 03:33:54 +08:00
|
|
|
INDEX
|
|
|
|
fseeko
|
2003-08-23 02:52:25 +08:00
|
|
|
INDEX
|
|
|
|
_fseek_r
|
|
|
|
INDEX
|
|
|
|
_fseeko_r
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
ANSI_SYNOPSIS
|
|
|
|
#include <stdio.h>
|
2015-11-03 05:34:49 +08:00
|
|
|
int fseek(FILE *<[fp]>, long <[offset]>, int <[whence]>);
|
|
|
|
int fseeko(FILE *<[fp]>, off_t <[offset]>, int <[whence]>);
|
2007-05-02 07:03:36 +08:00
|
|
|
int _fseek_r(struct _reent *<[ptr]>, FILE *<[fp]>,
|
2015-11-03 05:34:49 +08:00
|
|
|
long <[offset]>, int <[whence]>);
|
2007-05-02 07:03:36 +08:00
|
|
|
int _fseeko_r(struct _reent *<[ptr]>, FILE *<[fp]>,
|
2015-11-03 05:34:49 +08:00
|
|
|
off_t <[offset]>, int <[whence]>);
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
TRAD_SYNOPSIS
|
|
|
|
#include <stdio.h>
|
2015-11-03 05:34:49 +08:00
|
|
|
int fseek(<[fp]>, <[offset]>, <[whence]>);
|
2000-02-18 03:39:52 +08:00
|
|
|
FILE *<[fp]>;
|
|
|
|
long <[offset]>;
|
|
|
|
int <[whence]>;
|
|
|
|
|
2015-11-03 05:34:49 +08:00
|
|
|
int fseeko(<[fp]>, <[offset]>, <[whence]>);
|
2002-07-05 03:33:54 +08:00
|
|
|
FILE *<[fp]>;
|
|
|
|
off_t <[offset]>;
|
|
|
|
int <[whence]>;
|
|
|
|
|
2015-11-03 05:34:49 +08:00
|
|
|
int _fseek_r(<[ptr]>, <[fp]>, <[offset]>, <[whence]>);
|
2003-08-23 02:52:25 +08:00
|
|
|
struct _reent *<[ptr]>;
|
|
|
|
FILE *<[fp]>;
|
|
|
|
long <[offset]>;
|
|
|
|
int <[whence]>;
|
|
|
|
|
2015-11-03 05:34:49 +08:00
|
|
|
int _fseeko_r(<[ptr]>, <[fp]>, <[offset]>, <[whence]>);
|
2003-08-23 02:52:25 +08:00
|
|
|
struct _reent *<[ptr]>;
|
|
|
|
FILE *<[fp]>;
|
|
|
|
off_t <[offset]>;
|
|
|
|
int <[whence]>;
|
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
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
|
|
|
|
depend on this position, and many change it as a side effect.
|
|
|
|
|
2002-07-05 03:33:54 +08:00
|
|
|
You can use <<fseek>>/<<fseeko>> to set the position for the file identified by
|
2000-02-18 03:39:52 +08:00
|
|
|
<[fp]>. The value of <[offset]> determines the new position, in one
|
|
|
|
of three ways selected by the value of <[whence]> (defined as macros
|
|
|
|
in `<<stdio.h>>'):
|
|
|
|
|
|
|
|
<<SEEK_SET>>---<[offset]> is the absolute file position (an offset
|
|
|
|
from the beginning of the file) desired. <[offset]> must be positive.
|
|
|
|
|
|
|
|
<<SEEK_CUR>>---<[offset]> is relative to the current file position.
|
|
|
|
<[offset]> can meaningfully be either positive or negative.
|
|
|
|
|
|
|
|
<<SEEK_END>>---<[offset]> is relative to the current end of file.
|
|
|
|
<[offset]> can meaningfully be either positive (to increase the size
|
|
|
|
of the file) or negative.
|
|
|
|
|
2002-07-05 03:33:54 +08:00
|
|
|
See <<ftell>>/<<ftello>> to determine the current file position.
|
2000-02-18 03:39:52 +08:00
|
|
|
|
|
|
|
RETURNS
|
2002-07-05 03:33:54 +08:00
|
|
|
<<fseek>>/<<fseeko>> return <<0>> when successful. On failure, the
|
2000-02-18 03:39:52 +08:00
|
|
|
result is <<EOF>>. The reason for failure is indicated in <<errno>>:
|
|
|
|
either <<ESPIPE>> (the stream identified by <[fp]> doesn't support
|
|
|
|
repositioning) or <<EINVAL>> (invalid file position).
|
|
|
|
|
|
|
|
PORTABILITY
|
|
|
|
ANSI C requires <<fseek>>.
|
|
|
|
|
2002-07-05 03:33:54 +08:00
|
|
|
<<fseeko>> is defined by the Single Unix specification.
|
|
|
|
|
2000-02-18 03:39:52 +08:00
|
|
|
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
|
|
|
|
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
|
|
|
|
*/
|
|
|
|
|
2004-04-23 Artem B. Bityuckiy <abitytsky@softminecorp.com>
* libc/stdio/asprintf.c libc/stdio/clearerr.c,
libc/stdio/fclose.c libc/stdio/fcloseall.c libc/stdio/fdopen.c,
libc/stdio/feof.c libc/stdio/ferror.c libc/stdio/fflush.c,
libc/stdio/fgetc.c libc/stdio/fgetpos.c libc/stdio/fgets.c,
libc/stdio/fileno.c libc/stdio/findfp.c libc/stdio/fiprintf.c,
libc/stdio/flags.c libc/stdio/fopen.c libc/stdio/fprintf.c,
libc/stdio/fputc.c libc/stdio/fputs.c libc/stdio/fread.c,
libc/stdio/freopen.c libc/stdio/fscanf.c libc/stdio/fseek.c,
libc/stdio/fseeko.c libc/stdio/fsetpos.c libc/stdio/ftell.c,
libc/stdio/ftello.c libc/stdio/fvwrite.c libc/stdio/fwalk.c,
libc/stdio/fwrite.c libc/stdio/getc.c libc/stdio/getc_u.c,
libc/stdio/getchar.c libc/stdio/getchar_u.c,
libc/stdio/getdelim.c libc/stdio/getline.c libc/stdio/gets.c,
libc/stdio/getw.c libc/stdio/iprintf.c libc/stdio/local.h,
libc/stdio/makebuf.c libc/stdio/mktemp.c libc/stdio/perror.c,
libc/stdio/printf.c libc/stdio/putc.c libc/stdio/putc_u.c,
libc/stdio/putchar.c libc/stdio/putchar_u.c libc/stdio/puts.c,
libc/stdio/putw.c libc/stdio/refill.c libc/stdio/remove.c,
libc/stdio/rename.c libc/stdio/rewind.c libc/stdio/rget.c,
libc/stdio/scanf.c libc/stdio/setbuf.c libc/stdio/setbuffer.c,
libc/stdio/setlinebuf.c libc/stdio/setvbuf.c,
libc/stdio/siprintf.c libc/stdio/snprintf.c,
libc/stdio/sprintf.c libc/stdio/sscanf.c libc/stdio/stdio.c,
libc/stdio/tmpfile.c libc/stdio/tmpnam.c libc/stdio/ungetc.c,
libc/stdio/vasprintf.c libc/stdio/vfieeefp.h,
libc/stdio/vfprintf.c libc/stdio/vfscanf.c,
libc/stdio/vprintf.c libc/stdio/vscanf.c,
libc/stdio/vsnprintf.c libc/stdio/vsprintf.c,
libc/stdio/vsscanf.c libc/stdio/wbuf.c,
libc/stdio/wsetup.c: Perform minor formatting changes. Move
copyright notices to top of file, ensure that <_ansi.h> is
included, be consistent with open parentheses, use _DEFUN macro,
include "local.h" where needed, and remove various compiler
warnings.
2004-04-24 04:01:55 +08:00
|
|
|
#include <_ansi.h>
|
|
|
|
#include <reent.h>
|
2000-02-18 03:39:52 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "local.h"
|
|
|
|
|
|
|
|
int
|
2004-04-23 Artem B. Bityuckiy <abitytsky@softminecorp.com>
* libc/stdio/asprintf.c libc/stdio/clearerr.c,
libc/stdio/fclose.c libc/stdio/fcloseall.c libc/stdio/fdopen.c,
libc/stdio/feof.c libc/stdio/ferror.c libc/stdio/fflush.c,
libc/stdio/fgetc.c libc/stdio/fgetpos.c libc/stdio/fgets.c,
libc/stdio/fileno.c libc/stdio/findfp.c libc/stdio/fiprintf.c,
libc/stdio/flags.c libc/stdio/fopen.c libc/stdio/fprintf.c,
libc/stdio/fputc.c libc/stdio/fputs.c libc/stdio/fread.c,
libc/stdio/freopen.c libc/stdio/fscanf.c libc/stdio/fseek.c,
libc/stdio/fseeko.c libc/stdio/fsetpos.c libc/stdio/ftell.c,
libc/stdio/ftello.c libc/stdio/fvwrite.c libc/stdio/fwalk.c,
libc/stdio/fwrite.c libc/stdio/getc.c libc/stdio/getc_u.c,
libc/stdio/getchar.c libc/stdio/getchar_u.c,
libc/stdio/getdelim.c libc/stdio/getline.c libc/stdio/gets.c,
libc/stdio/getw.c libc/stdio/iprintf.c libc/stdio/local.h,
libc/stdio/makebuf.c libc/stdio/mktemp.c libc/stdio/perror.c,
libc/stdio/printf.c libc/stdio/putc.c libc/stdio/putc_u.c,
libc/stdio/putchar.c libc/stdio/putchar_u.c libc/stdio/puts.c,
libc/stdio/putw.c libc/stdio/refill.c libc/stdio/remove.c,
libc/stdio/rename.c libc/stdio/rewind.c libc/stdio/rget.c,
libc/stdio/scanf.c libc/stdio/setbuf.c libc/stdio/setbuffer.c,
libc/stdio/setlinebuf.c libc/stdio/setvbuf.c,
libc/stdio/siprintf.c libc/stdio/snprintf.c,
libc/stdio/sprintf.c libc/stdio/sscanf.c libc/stdio/stdio.c,
libc/stdio/tmpfile.c libc/stdio/tmpnam.c libc/stdio/ungetc.c,
libc/stdio/vasprintf.c libc/stdio/vfieeefp.h,
libc/stdio/vfprintf.c libc/stdio/vfscanf.c,
libc/stdio/vprintf.c libc/stdio/vscanf.c,
libc/stdio/vsnprintf.c libc/stdio/vsprintf.c,
libc/stdio/vsscanf.c libc/stdio/wbuf.c,
libc/stdio/wsetup.c: Perform minor formatting changes. Move
copyright notices to top of file, ensure that <_ansi.h> is
included, be consistent with open parentheses, use _DEFUN macro,
include "local.h" where needed, and remove various compiler
warnings.
2004-04-24 04:01:55 +08:00
|
|
|
_DEFUN(_fseek_r, (ptr, fp, offset, whence),
|
|
|
|
struct _reent *ptr _AND
|
|
|
|
register FILE *fp _AND
|
|
|
|
long offset _AND
|
|
|
|
int whence)
|
2000-02-18 03:39:52 +08:00
|
|
|
{
|
2012-11-30 00:28:30 +08:00
|
|
|
return _fseeko_r (ptr, fp, offset, whence);
|
2000-02-18 03:39:52 +08:00
|
|
|
}
|
2003-08-23 02:52:25 +08:00
|
|
|
|
|
|
|
#ifndef _REENT_ONLY
|
|
|
|
|
|
|
|
int
|
2004-04-23 Artem B. Bityuckiy <abitytsky@softminecorp.com>
* libc/stdio/asprintf.c libc/stdio/clearerr.c,
libc/stdio/fclose.c libc/stdio/fcloseall.c libc/stdio/fdopen.c,
libc/stdio/feof.c libc/stdio/ferror.c libc/stdio/fflush.c,
libc/stdio/fgetc.c libc/stdio/fgetpos.c libc/stdio/fgets.c,
libc/stdio/fileno.c libc/stdio/findfp.c libc/stdio/fiprintf.c,
libc/stdio/flags.c libc/stdio/fopen.c libc/stdio/fprintf.c,
libc/stdio/fputc.c libc/stdio/fputs.c libc/stdio/fread.c,
libc/stdio/freopen.c libc/stdio/fscanf.c libc/stdio/fseek.c,
libc/stdio/fseeko.c libc/stdio/fsetpos.c libc/stdio/ftell.c,
libc/stdio/ftello.c libc/stdio/fvwrite.c libc/stdio/fwalk.c,
libc/stdio/fwrite.c libc/stdio/getc.c libc/stdio/getc_u.c,
libc/stdio/getchar.c libc/stdio/getchar_u.c,
libc/stdio/getdelim.c libc/stdio/getline.c libc/stdio/gets.c,
libc/stdio/getw.c libc/stdio/iprintf.c libc/stdio/local.h,
libc/stdio/makebuf.c libc/stdio/mktemp.c libc/stdio/perror.c,
libc/stdio/printf.c libc/stdio/putc.c libc/stdio/putc_u.c,
libc/stdio/putchar.c libc/stdio/putchar_u.c libc/stdio/puts.c,
libc/stdio/putw.c libc/stdio/refill.c libc/stdio/remove.c,
libc/stdio/rename.c libc/stdio/rewind.c libc/stdio/rget.c,
libc/stdio/scanf.c libc/stdio/setbuf.c libc/stdio/setbuffer.c,
libc/stdio/setlinebuf.c libc/stdio/setvbuf.c,
libc/stdio/siprintf.c libc/stdio/snprintf.c,
libc/stdio/sprintf.c libc/stdio/sscanf.c libc/stdio/stdio.c,
libc/stdio/tmpfile.c libc/stdio/tmpnam.c libc/stdio/ungetc.c,
libc/stdio/vasprintf.c libc/stdio/vfieeefp.h,
libc/stdio/vfprintf.c libc/stdio/vfscanf.c,
libc/stdio/vprintf.c libc/stdio/vscanf.c,
libc/stdio/vsnprintf.c libc/stdio/vsprintf.c,
libc/stdio/vsscanf.c libc/stdio/wbuf.c,
libc/stdio/wsetup.c: Perform minor formatting changes. Move
copyright notices to top of file, ensure that <_ansi.h> is
included, be consistent with open parentheses, use _DEFUN macro,
include "local.h" where needed, and remove various compiler
warnings.
2004-04-24 04:01:55 +08:00
|
|
|
_DEFUN(fseek, (fp, offset, whence),
|
|
|
|
register FILE *fp _AND
|
|
|
|
long offset _AND
|
|
|
|
int whence)
|
2003-08-23 02:52:25 +08:00
|
|
|
{
|
|
|
|
return _fseek_r (_REENT, fp, offset, whence);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !_REENT_ONLY */
|