.\" Copyright (c) 1990, 1991, 1993 .\" 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 8.1 (Berkeley) 6/4/93 .\" %FreeBSD: src/lib/libc/stdio/fseek.3,v 1.5.2.7 2001/12/14 18:33:57 ru Exp % .\" $FreeBSD$ .\" .Dd March 5, 1999 .Dt FSEEK 3 .Os .Sh 名称 .Nm fgetpos , .Nm fseek , .Nm fseeko , .Nm fsetpos , .Nm ftell , .Nm ftello , .Nm rewind .Nd ストリームの位置変更 .Sh ライブラリ .Lb libc .Sh 書式 .In stdio.h .Ft int .Fn fseek "FILE *stream" "long offset" "int whence" .Ft long .Fn ftell "FILE *stream" .Ft void .Fn rewind "FILE *stream" .Ft int .Fn fgetpos "FILE *stream" "fpos_t *pos" .Ft int .Fn fsetpos "FILE *stream" "const fpos_t *pos" .In sys/types.h .Ft int .Fn fseeko "FILE *stream" "off_t offset" "int whence" .Ft off_t .Fn ftello "FILE *stream" .Sh 解説 .Fn fseek 関数は、 .Fa stream が指すストリームのファイル位置インジケータを 設定します。新しい位置はバイト単位で計測され、 .Fa whence で指定された位置に .Fa offset バイトを足すことで得られます。 .Fa whence が .Dv SEEK_SET , .Dv SEEK_CUR , .Dv SEEK_END に設定されている場合、オフセットは、それぞれ、ファイルの最初、 インジケータの現在位置、ファイルの最後からの相対位置になります。 .Fn fseek 関数の呼び出しで 問題が発生しない場合は、ストリームの end-of-file 指示子がクリアされ、 そのストリームに対する .Xr ungetc 3 関数の効果は取り消されます。 .Pp .Fn ftell 関数は、 .Fa stream が指すストリームのファイル位置インジケータの 現在の値を入手します。 .Pp .Fn rewind 関数は、 .Fa stream が指すストリームのファイル位置インジケータを ファイルの最初に設定します。これは、 ストリームのエラーインジケータがクリアされること ( .Xr clearerr 3 を参照) を除けば、以下と同じ結果になります。 .Pp .Dl (void)fseek(stream, 0L, SEEK_SET) .Pp .Fn fseeko 関数は .Fn fseek と同様ですが、 引数には .Fa long の代わりに .Fa off_t をとります。 同様に .Fn ftello 関数は .Fn ftell と同じですが、 .Fa off_t を返します。 .Pp .Fn fgetpos 関数と .Fn fsetpos 関数は、( whence を .Dv SEEK_SET に設定した ) .Fn ftell や .Fn fseek と同じインタフェースで、ファイルオフセットの現在の値を .Fa pos が参照するオブジェクトから設定したり、 .Fa pos が参照するオブジェクトに保存したりします。 一部の .Pq Tn UNIX 以外の システムでは、 .Dq Fa fpos_t オブジェクトが複合オブジェクトであるかもしれないので、 移植性を保ちながらテキストストリームの位置を 変更するためには、このルーチンに依るしかないこともあります。 .Sh 戻り値 .Fn rewind 関数は値を返しません。 .Pp .Rv -std fgetpos fseek fseeko fsetpos .Pp 成功して終了すると、 .Fn ftell および .Fn ftello は現在のオフセットを返します。それ以外の場合は \-1 が返され、 グローバル変数 .Va errno が設定されてエラーを示します。 .Sh エラー .Bl -tag -width Er .It Bq Er EBADF 指定された .Fa stream が、シークできるストリームではありません。 .It Bq Er EINVAL .Fn fseek の .Fa whence 引数が、 .Dv SEEK_SET , .Dv SEEK_END , .Dv SEEK_CUR のどれでもありません。 .It Bq Er EOVERFLOW .Fn ftell を実行した結果のファイルのオフセットが long 型のオブジェクトでは正しく表現できない値となりました。 .El .Pp .Fn fgetpos , .Fn fseek , .Fn fseeko , .Fn fsetpos , .Fn ftell , .Fn ftello 関数が失敗した時には、 ルーチン .Xr fflush 3 , .Xr fstat 2 , .Xr lseek 2 , .Xr malloc 3 について示しているエラーが .Va errno に設定されていることもあります。 .Sh 関連項目 .Xr lseek 2 .Sh 規格 .Fn fgetpos , .Fn fsetpos , .Fn fseek , .Fn ftell , .Fn rewind 関数は、 .St -isoC に適合しています。 .Pp .Fn fseeko と .Fn ftello 関数は、 .St -susv2 に適合しています。 .\"X kuma 1999-11-6