2004-11-03 13:51:07 +00:00
|
|
|
.\" Copyright (c) 1990, 1991 The Regents of the University of California.
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" This code is derived from software contributed to Berkeley by
|
|
|
|
.\" Chris Torek and the American National Standards Committee X3,
|
|
|
|
.\" on Information Processing Systems.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the University of
|
|
|
|
.\" California, Berkeley and its contributors.
|
|
|
|
.\" 4. Neither the name of the University nor the names of its contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" @(#)fseek.3 6.11 (Berkeley) 6/29/91
|
|
|
|
.\"
|
|
|
|
.\" Converted for Linux, Mon Nov 29 15:22:01 1993, faith@cs.unc.edu
|
|
|
|
.\"
|
2007-05-18 09:55:10 +00:00
|
|
|
.TH FSEEK 3 1993-11-29 "GNU" "Linux Programmer's Manual"
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH NAME
|
|
|
|
fgetpos, fseek, fsetpos, ftell, rewind \- reposition a stream
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.B #include <stdio.h>
|
|
|
|
.sp
|
|
|
|
.BI "int fseek(FILE *" stream ", long " offset ", int " whence );
|
2007-12-23 13:45:24 +00:00
|
|
|
|
2004-11-03 13:51:07 +00:00
|
|
|
.BI "long ftell(FILE *" stream );
|
2007-12-23 13:45:24 +00:00
|
|
|
|
2004-11-03 13:51:07 +00:00
|
|
|
.BI "void rewind(FILE *" stream );
|
2007-12-23 13:45:24 +00:00
|
|
|
|
2004-11-03 13:51:07 +00:00
|
|
|
.BI "int fgetpos(FILE *" stream ", fpos_t *" pos );
|
|
|
|
.br
|
|
|
|
.BI "int fsetpos(FILE *" stream ", fpos_t *" pos );
|
|
|
|
.SH DESCRIPTION
|
|
|
|
The
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR fseek ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function sets the file position indicator for the stream pointed to by
|
|
|
|
.IR stream .
|
|
|
|
The new position, measured in bytes, is obtained by adding
|
|
|
|
.I offset
|
|
|
|
bytes to the position specified by
|
|
|
|
.IR whence .
|
|
|
|
If
|
|
|
|
.I whence
|
|
|
|
is set to
|
|
|
|
.BR SEEK_SET ,
|
|
|
|
.BR SEEK_CUR ,
|
|
|
|
or
|
|
|
|
.BR SEEK_END ,
|
|
|
|
the offset is relative to the start of the file, the current position
|
2007-04-12 22:42:49 +00:00
|
|
|
indicator, or end-of-file, respectively.
|
|
|
|
A successful call to the
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR fseek ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function clears the end-of-file indicator for the stream and undoes
|
|
|
|
any effects of the
|
|
|
|
.BR ungetc (3)
|
|
|
|
function on the same stream.
|
|
|
|
.PP
|
|
|
|
The
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR ftell ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function obtains the current value of the file position indicator for the
|
|
|
|
stream pointed to by
|
|
|
|
.IR stream .
|
|
|
|
.PP
|
|
|
|
The
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR rewind ()
|
2004-11-03 13:51:07 +00:00
|
|
|
function sets the file position indicator for the stream pointed to by
|
|
|
|
.I stream
|
2007-04-12 22:42:49 +00:00
|
|
|
to the beginning of the file.
|
|
|
|
It is equivalent to:
|
2004-11-03 13:51:07 +00:00
|
|
|
.PP
|
|
|
|
.RS
|
2007-05-21 08:47:38 +00:00
|
|
|
(void) fseek(stream, 0L, SEEK_SET)
|
2004-11-03 13:51:07 +00:00
|
|
|
.RE
|
|
|
|
.PP
|
|
|
|
except that the error indicator for the stream is also cleared (see
|
|
|
|
.BR clearerr (3)).
|
|
|
|
.PP
|
|
|
|
The
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR fgetpos ()
|
2004-11-03 13:51:07 +00:00
|
|
|
and
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR fsetpos ()
|
2004-11-03 13:51:07 +00:00
|
|
|
functions are alternate interfaces equivalent to
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR ftell ()
|
2004-11-03 13:51:07 +00:00
|
|
|
and
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR fseek ()
|
2004-11-03 13:51:07 +00:00
|
|
|
(with whence set to
|
|
|
|
.BR SEEK_SET ),
|
|
|
|
setting and storing the current value of the file offset into or from the
|
|
|
|
object referenced by
|
|
|
|
.IR pos .
|
intro.1, time.1, accept.2, bind.2, connect.2, execve.2, flock.2, getdents.2, getpriority.2, getuid.2, intro.2, ioctl.2, mincore.2, mknod.2, personality.2, ptrace.2, read.2, recv.2, select_tut.2, send.2, sendfile.2, shmctl.2, sigaction.2, signal.2, stat.2, times.2, truncate.2, umask.2, wait.2, MB_CUR_MAX.3, MB_LEN_MAX.3, argz_add.3, btowc.3, clearenv.3, clock.3, cmsg.3, end.3, endian.3, errno.3, exit.3, fgetwc.3, fgetws.3, fopen.3, fputwc.3, fputws.3, fseek.3, fwide.3, getfsent.3, getgrnam.3, gethostid.3, getipnodebyname.3, getmntent.3, getpwnam.3, getwchar.3, grantpt.3, iconv.3, iconv_close.3, iconv_open.3, insque.3, intro.3, iswalnum.3, iswalpha.3, iswblank.3, iswcntrl.3, iswctype.3, iswdigit.3, iswgraph.3, iswlower.3, iswprint.3, iswpunct.3, iswspace.3, iswupper.3, iswxdigit.3, malloc.3, mblen.3, mbrlen.3, mbrtowc.3, mbsinit.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mkstemp.3, mktemp.3, nl_langinfo.3, openpty.3, posix_openpt.3, printf.3, ptsname.3, putwchar.3, qecvt.3, rcmd.3, readdir.3, rexec.3, rpc.3, setnetgrent.3, shm_open.3, sigpause.3, stdin.3, stpcpy.3, strftime.3, strptime.3, syslog.3, towctrans.3, towlower.3, towupper.3, ttyslot.3, ungetwc.3, unlocked_stdio.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscasecmp.3, wcscat.3, wcschr.3, wcscmp.3, wcscpy.3, wcscspn.3, wcsdup.3, wcslen.3, wcsncasecmp.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcspbrk.3, wcsrchr.3, wcsrtombs.3, wcsspn.3, wcsstr.3, wcstok.3, wcstombs.3, wcswidth.3, wctob.3, wctomb.3, wctrans.3, wctype.3, wcwidth.3, wmemchr.3, wmemcmp.3, wmemcpy.3, wmemmove.3, wmemset.3, wprintf.3, console_ioctl.4, pts.4, elf.5, filesystems.5, hosts.5, proc.5, ttytype.5, boot.7, capabilities.7, credentials.7, epoll.7, glob.7, koi8-r.7, path_resolution.7, pty.7, signal.7, suffixes.7, time.7, unicode.7, unix.7, uri.7, utf-8.7: global fix: s/Unix/UNIX/
The man pages were rather inconsistent in the use of "Unix"
versus "UNIX". Let's go with the trademark usage.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2010-10-12 04:45:38 +00:00
|
|
|
On some non-UNIX systems an
|
2007-06-23 07:56:56 +00:00
|
|
|
.I fpos_t
|
2004-11-03 13:51:07 +00:00
|
|
|
object may be a complex object and these routines may be the only way to
|
|
|
|
portably reposition a text stream.
|
|
|
|
.SH "RETURN VALUE"
|
|
|
|
The
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR rewind ()
|
2007-04-12 22:42:49 +00:00
|
|
|
function returns no value.
|
|
|
|
Upon successful completion,
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR fgetpos (),
|
|
|
|
.BR fseek (),
|
|
|
|
.BR fsetpos ()
|
2004-11-03 13:51:07 +00:00
|
|
|
return 0,
|
|
|
|
and
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR ftell ()
|
2007-04-12 22:42:49 +00:00
|
|
|
returns the current offset.
|
|
|
|
Otherwise, \-1 is returned and
|
|
|
|
.I errno
|
2006-01-13 09:34:01 +00:00
|
|
|
is set to indicate the error.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH ERRORS
|
|
|
|
.TP
|
|
|
|
.B EBADF
|
|
|
|
The
|
|
|
|
.I stream
|
|
|
|
specified is not a seekable stream.
|
|
|
|
.TP
|
|
|
|
.B EINVAL
|
|
|
|
The
|
|
|
|
.I whence
|
2007-04-12 22:42:49 +00:00
|
|
|
argument to
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR fseek ()
|
2004-11-03 13:51:07 +00:00
|
|
|
was not
|
|
|
|
.BR SEEK_SET ,
|
|
|
|
.BR SEEK_END ,
|
|
|
|
or
|
|
|
|
.BR SEEK_CUR .
|
|
|
|
.PP
|
2006-01-13 09:34:01 +00:00
|
|
|
The functions
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR fgetpos (),
|
|
|
|
.BR fseek (),
|
|
|
|
.BR fsetpos (),
|
2007-04-12 22:42:49 +00:00
|
|
|
and
|
2005-10-19 06:54:38 +00:00
|
|
|
.BR ftell ()
|
2004-11-03 13:51:07 +00:00
|
|
|
may also fail and set
|
|
|
|
.I errno
|
|
|
|
for any of the errors specified for the routines
|
|
|
|
.BR fflush (3),
|
|
|
|
.BR fstat (2),
|
|
|
|
.BR lseek (2),
|
2007-04-12 22:42:49 +00:00
|
|
|
and
|
2004-11-03 13:51:07 +00:00
|
|
|
.BR malloc (3).
|
|
|
|
.SH "CONFORMING TO"
|
2006-08-03 13:57:30 +00:00
|
|
|
C89, C99.
|
2004-11-03 13:51:07 +00:00
|
|
|
.SH "SEE ALSO"
|
|
|
|
.BR lseek (2),
|
|
|
|
.BR fseeko (3)
|