OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / man3 / fseek.3
1 .\" Copyright (c) 1990, 1991 The Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" Chris Torek and the American National Standards Committee X3,
6 .\" on Information Processing Systems.
7 .\"
8 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
11 .\" are met:
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\"    notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\"    notice, this list of conditions and the following disclaimer in the
16 .\"    documentation and/or other materials provided with the distribution.
17 .\" 3. All advertising materials mentioning features or use of this software
18 .\"    must display the following acknowledgement:
19 .\"     This product includes software developed by the University of
20 .\"     California, Berkeley and its contributors.
21 .\" 4. Neither the name of the University nor the names of its contributors
22 .\"    may be used to endorse or promote products derived from this software
23 .\"    without specific prior written permission.
24 .\"
25 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .\" SUCH DAMAGE.
36 .\" %%%LICENSE_END
37 .\"
38 .\"     @(#)fseek.3     6.11 (Berkeley) 6/29/91
39 .\"
40 .\" Converted for Linux, Mon Nov 29 15:22:01 1993, faith@cs.unc.edu
41 .\"
42 .TH FSEEK 3  2014-05-28 "GNU" "Linux Programmer's Manual"
43 .SH NAME
44 fgetpos, fseek, fsetpos, ftell, rewind \- reposition a stream
45 .SH SYNOPSIS
46 .B #include <stdio.h>
47 .sp
48 .BI "int fseek(FILE *" stream ", long " offset ", int " whence );
49
50 .BI "long ftell(FILE *" stream );
51
52 .BI "void rewind(FILE *" stream );
53
54 .BI "int fgetpos(FILE *" stream ", fpos_t *" pos );
55 .br
56 .BI "int fsetpos(FILE *" stream ", const fpos_t *" pos );
57 .SH DESCRIPTION
58 The
59 .BR fseek ()
60 function sets the file position indicator for the stream pointed to by
61 .IR stream .
62 The new position, measured in bytes, is obtained by adding
63 .I offset
64 bytes to the position specified by
65 .IR whence .
66 If
67 .I whence
68 is set to
69 .BR SEEK_SET ,
70 .BR SEEK_CUR ,
71 or
72 .BR SEEK_END ,
73 the offset is relative to the start of the file, the current position
74 indicator, or end-of-file, respectively.
75 A successful call to the
76 .BR fseek ()
77 function clears the end-of-file indicator for the stream and undoes
78 any effects of the
79 .BR ungetc (3)
80 function on the same stream.
81 .PP
82 The
83 .BR ftell ()
84 function obtains the current value of the file position indicator for the
85 stream pointed to by
86 .IR stream .
87 .PP
88 The
89 .BR rewind ()
90 function sets the file position indicator for the stream pointed to by
91 .I stream
92 to the beginning of the file.
93 It is equivalent to:
94 .PP
95 .RS
96 (void) fseek(stream, 0L, SEEK_SET)
97 .RE
98 .PP
99 except that the error indicator for the stream is also cleared (see
100 .BR clearerr (3)).
101 .PP
102 The
103 .BR fgetpos ()
104 and
105 .BR fsetpos ()
106 functions are alternate interfaces equivalent to
107 .BR ftell ()
108 and
109 .BR fseek ()
110 (with
111 .I whence
112 set to
113 .BR SEEK_SET ),
114 setting and storing the current value of the file offset into or from the
115 object referenced by
116 .IR pos .
117 On some non-UNIX systems, an
118 .I fpos_t
119 object may be a complex object and these routines may be the only way to
120 portably reposition a text stream.
121 .SH RETURN VALUE
122 The
123 .BR rewind ()
124 function returns no value.
125 Upon successful completion,
126 .BR fgetpos (),
127 .BR fseek (),
128 .BR fsetpos ()
129 return 0,
130 and
131 .BR ftell ()
132 returns the current offset.
133 Otherwise, \-1 is returned and
134 .I errno
135 is set to indicate the error.
136 .SH ERRORS
137 .TP
138 .B EBADF
139 The
140 .I stream
141 specified is not a seekable stream.
142 .TP
143 .B EINVAL
144 The
145 .I whence
146 argument to
147 .BR fseek ()
148 was not
149 .BR SEEK_SET ,
150 .BR SEEK_END ,
151 or
152 .BR SEEK_CUR .
153 Or: the resulting file offset would be negative.
154 .PP
155 The functions
156 .BR fgetpos (),
157 .BR fseek (),
158 .BR fsetpos (),
159 and
160 .BR ftell ()
161 may also fail and set
162 .I errno
163 for any of the errors specified for the routines
164 .BR fflush (3),
165 .BR fstat (2),
166 .BR lseek (2),
167 and
168 .BR malloc (3).
169 .SH CONFORMING TO
170 C89, C99.
171 .SH SEE ALSO
172 .BR lseek (2),
173 .BR fseeko (3)
174 .SH COLOPHON
175 This page is part of release 3.79 of the Linux
176 .I man-pages
177 project.
178 A description of the project,
179 information about reporting bugs,
180 and the latest version of this page,
181 can be found at
182 \%http://www.kernel.org/doc/man\-pages/.