.\" 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. .\" .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB) .\" 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. .\" %%%LICENSE_END .\" .\" @(#)fseek.3 6.11 (Berkeley) 6/29/91 .\" .\" Converted for Linux, Mon Nov 29 15:22:01 1993, faith@cs.unc.edu .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 1998 NAKANO Takeo all rights reserved. .\" Translated Mon Apr 27 1998 by NAKANO Takeo .\" .TH FSEEK 3 2014\-05\-28 GNU "Linux Programmer's Manual" .SH 名前 fgetpos, fseek, fsetpos, ftell, rewind \- ストリームの位置を変更する .SH 書式 \fB#include \fP .sp \fBint fseek(FILE *\fP\fIstream\fP\fB, long \fP\fIoffset\fP\fB, int \fP\fIwhence\fP\fB);\fP \fBlong ftell(FILE *\fP\fIstream\fP\fB);\fP \fBvoid rewind(FILE *\fP\fIstream\fP\fB);\fP \fBint fgetpos(FILE *\fP\fIstream\fP\fB, fpos_t *\fP\fIpos\fP\fB);\fP .br \fBint fsetpos(FILE *\fP\fIstream\fP\fB, const fpos_t *\fP\fIpos\fP\fB);\fP .SH 説明 \fBfseek\fP() 関数は \fIstream\fP によって指定されたストリームにおいて、ファイル位置表示子 (file position indicator) をセットする。新たな位置 (バイト単位) は \fIwhence\fP で指定された位置に \fIoffset\fP バイトを加えることによって与えられる。 \fIwhence\fP が \fBSEEK_SET\fP, \fBSEEK_CUR\fP, \fBSEEK_END\fP のどれかになっている場合は、それぞれファイルの先頭、現在の位置表示子、 ファイルの末尾からのオフセットが取られる。 \fBfseek\fP() 関数の呼び出しが成功すると、ストリームの end\-of\-file 表示子は クリアされ、それまでに \fBungetc\fP(3) 関数で戻したデータはなかったことになる。 .PP \fBftell\fP() 関数は \fIstream\fP によって指定されたストリームにおける、ファイル位置表示子 の現時点での値を与える。 .PP \fBrewind\fP() 関数は \fIstream\fP によって指定されたストリームにおいて、ファイル位置表示子 をファイルの先頭にセットする。この関数は以下と等価である。 .PP .RS (void) fseek(stream, 0L, SEEK_SET) .RE .PP ただし \fBrewind\fP() ではストリームに対するエラー表示子 (error indicator) も同時に クリアされる ( \fBclearerr\fP(3) を見よ)。 .PP \fBfgetpos\fP() 関数と \fBfsetpos\fP() 関数は、それぞれ \fBftell\fP() と \fBfseek\fP() で \fIwhence\fP に \fBSEEK_SET\fP を指定した場合と同様の機能を、異なるインターフェースで提供する。 \fBfgetpos\fP() はファイルオフセットの現在の値を \fIpos\fP が参照するオブジェクトに保存し、 \fBfsetpos\fP() はファイルオフセットを \fIpos\fP に設定する。 UNIX 以外のシステムにおいては、 \fIfpos_t\fP が構造体などの複雑なオブジェクトになっていて、これらのルーチンがテキス トストリームでファイル位置を変更する方法のうち、移植性のある唯一のもの になっている場合もある。 .SH 返り値 \fBrewind\fP() は返り値を持たない。 \fBfgetpos\fP(), \fBfseek\fP(), \fBfsetpos\fP() は成功すると 0 を返す。 \fBftell\fP() は現在のオフセットを返す。失敗した場合は返り値は \-1 となり、 \fIerrno\fP にエラーを示す値がセットされる。 .SH エラー .TP \fBEBADF\fP 指定した \fIstream\fP がシークできない。 .TP \fBEINVAL\fP \fBfseek\fP() 関数に対して与えた \fIwhence\fP 引数が \fBSEEK_SET\fP, \fBSEEK_END\fP, \fBSEEK_CUR\fP 以外の値であった。 または、更新後のファイルオフセットが負になってしまう。 .PP \fBfgetpos\fP(), \fBfseek\fP(), \fBfsetpos\fP(), \fBftell\fP() は、それぞれ \fBfflush\fP(3), \fBfstat\fP(2), \fBlseek\fP(2), \fBmalloc\fP(3) などのルーチンを呼び出す際に失敗する可能性がある。この場合は それぞれ対応した \fIerrno\fP が設定される。 .SH 準拠 C89, C99. .SH 関連項目 \fBlseek\fP(2), \fBfseeko\fP(3) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。