fseekのヘルプ・マニュアル
日本語 英語
fseek --help
man fseek
FSEEK(3) Linux Programmer’s Manual FSEEK(3)
名前
fgetpos, fseek, fsetpos, ftell, rewind - ストリームの位置を変更する
書式
#include
int fseek(FILE *stream, long offset, int whence);
long ftell(FILE *stream);
void rewind(FILE *stream);
int fgetpos(FILE *stream, fpos_t *pos);
int fsetpos(FILE *stream, fpos_t *pos);
説明
fseek() 関数は stream によって指定されたストリームにおいて、ファイル位
置表示子 (file position indicator) をセットする。新たな位置 (バイ ト 単
位) は whence で指定された位置に offset バイトを加えることによって与え
られる。 whence が SEEK_SET, SEEK_CUR, SEEK_END のどれかになっている 場
合 は、それぞれファイルの先頭、現在の位置表示子、ファイルの末尾からのオ
フセットが取られる。 fseek() 関数の呼び出しが成功すると、ストリー ム の
end-of-file 表示子はクリアされ、それまでに ungetc(3) 関数で戻したデータ
はなかったことになる。
ftell() 関数は stream によって指定されたストリームにおける、ファイル 位
置表示子の現時点での値を与える。
rewind() 関数は stream によって指定されたストリームにおいて、ファイル位
置表示子をファイルの先頭にセットする。この関数は以下と等価である。
(void) fseek(stream, 0L, SEEK_SET)
ただし rewind() ではストリームに対するエラー表示子 (error indicator) も
同時にクリアされる ( clearerr(3) を見よ)。
fgetpos() 関 数 と fsetpos() 関数は、それぞれ ftell() と fseek() で
whence に SEEK_SET を指定した場合と同様の機能を、異なるインターフェース
で 提供する。 fgetpos() はファイルオフセットの現在の値を pos が参照する
オブジェクトに保存し、 fsetpos() はファイルオフセットを pos に設定す る
。 Unix 以外のシステムにおいては、 fpos_t が構造体などの複雑なオブジェ
クトになっていて、これらのルーチンがテキストストリームでファイル位置 を
変更する方法のうち、移植性のある唯一のものになっている場合もある。
返り値
rewind() は返り値を持たない。 fgetpos(), fseek(), fsetpos() は成功する
と 0 を返す。 ftell() は現在のオフセットを返す。失敗した場合は返り値 は
-1 となり、 errno にエラーを示す値がセットされる。
エラー
EBADF 指定した stream がシークできない。
EINVAL fseek() 関 数 に対して与えた whence 引数が SEEK_SET, SEEK_END,
SEEK_CUR 以外の値であった。
fgetpos(), fseek(), fsetpos(), ftell() は 、 そ れ ぞ れ fflush(3),
fstat(2), lseek(2), malloc(3) などのルーチンを呼び出す際に失敗する可能
性がある。この場合はそれぞれ対応した errno が設定される。
準拠
C89, C99.
関連項目
lseek(2), fseeko(3)
GNU 1993-11-29 FSEEK(3)
FSEEK(3) Linux Programmer’s Manual FSEEK(3)
NAME
fgetpos, fseek, fsetpos, ftell, rewind - reposition a stream
SYNOPSIS
#include
int fseek(FILE *stream, long offset, int whence);
long ftell(FILE *stream);
void rewind(FILE *stream);
int fgetpos(FILE *stream, fpos_t *pos);
int fsetpos(FILE *stream, fpos_t *pos);
DESCRIPTION
The fseek() function sets the file position indicator for the stream
pointed to by stream. The new position, measured in bytes, is obtained
by adding offset bytes to the position specified by whence. If whence
is set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to
the start of the file, the current position indicator, or end-of-file,
respectively. A successful call to the fseek() function clears the
end-of-file indicator for the stream and undoes any effects of the
ungetc(3) function on the same stream.
The ftell() function obtains the current value of the file position
indicator for the stream pointed to by stream.
The rewind() function sets the file position indicator for the stream
pointed to by stream to the beginning of the file. It is equivalent
to:
(void) fseek(stream, 0L, SEEK_SET)
except that the error indicator for the stream is also cleared (see
clearerr(3)).
The fgetpos() and fsetpos() functions are alternate interfaces equiva-
lent to ftell() and fseek() (with whence set to SEEK_SET), setting and
storing the current value of the file offset into or from the object
referenced by pos. On some non-Unix systems an fpos_t object may be a
complex object and these routines may be the only way to portably repo-
sition a text stream.
RETURN VALUE
The rewind() function returns no value. Upon successful completion,
fgetpos(), fseek(), fsetpos() return 0, and ftell() returns the current
offset. Otherwise, -1 is returned and errno is set to indicate the
error.
ERRORS
EBADF The stream specified is not a seekable stream.
EINVAL The whence argument to fseek() was not SEEK_SET, SEEK_END, or
SEEK_CUR.
The functions fgetpos(), fseek(), fsetpos(), and ftell() may also fail
and set errno for any of the errors specified for the routines
fflush(3), fstat(2), lseek(2), and malloc(3).
CONFORMING TO
C89, C99.
SEE ALSO
lseek(2), fseeko(3)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU 1993-11-29 FSEEK(3)