1 .\" Copyright (c) 1980, 1991 Regents of the University of California.
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)lseek.2 6.5 (Berkeley) 3/10/91
34 .\" Modified Fri Jul 23 22:17:00 1993 by Rik Faith <faith@cs.unc.edu>
35 .\" Modified 10 June 1995 by Andries Brouwer <aeb@cwi.nl>
36 .\" Modified Thu Oct 31 15:18:33 1996 by Eric S. Raymond <esr@thyrsus.com>
37 .\" Modified Sat Jan 17 13:00:32 MET 1998 by Michael Haardt
38 .\" <michael@cantor.informatik.rwth-aachen.de>
39 .\" Modified Mon Sep 24 16:18:02 CEST 2001 by Michael Haardt <michael@moria.de>
41 .\" Japanese Version Copyright (c) 1997-1998 HANATAKA Shinya
42 .\" all rights reserved.
43 .\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
44 .\" Modified 1998-05-11, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
45 .\" Updated 2001-12-14, Kentaro Shirakata <argrath@ub32.org>
46 .\" Updated 2003-09-08, Kentaro Shirakata <argrath@ub32.org>
47 .\" Updated 2005-02-24, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
48 .\" Updated 2006-03-05, Akihiro MOTOKI, catch up to LDP v2.25
50 .\"WORD: end-of-file ファイルの終端(end-of-file)
52 .TH LSEEK 2 2010-09-11 "Linux" "Linux Programmer's Manual"
54 lseek \- ファイルの読み書きオフセットの位置を変える
56 .B #include <sys/types.h>
58 .B #include <unistd.h>
60 .BI "off_t lseek(int " fd ", off_t " offset ", int " whence );
64 .\"O function repositions the offset of the open file associated with the
69 .\"O according to the directive
73 関数は、ファイルディスクリプタ (descriptor)
75 に対応するオープンされたファイルのオフセットを、
82 .\"O The offset is set to
90 .\"O The offset is set to its current location plus
98 .\"O The offset is set to the size of the file plus
107 .\"O function allows the file offset to be set beyond the end
108 .\"O of the file (but this does not change the size of the file).
109 .\"O If data is later written at this point, subsequent reads of the data
110 .\"O in the gap (a "hole") return null bytes (\(aq\\0\(aq) until
111 .\"O data is actually written into the gap.
113 関数は、オフセットをファイルの末尾を越えた位置に設定できる
114 (但し、これによりファイルのサイズが変わらない)。
115 もしデータがこのオフセット位置以降に書き込まれた場合、
116 間の空隙の部分 ("穴 (hole)") の読み出しがあると、
118 NULL バイト (\(aq\\0\(aq) の列が返される。
119 .\"O .SH "RETURN VALUE"
121 .\"O Upon successful completion,
123 .\"O returns the resulting offset location as measured in bytes from the
124 .\"O beginning of the file.
125 .\"O On error, the value \fI(off_t)\ \-1\fP is returned and
127 .\"O is set to indicate the error.
130 は結果のファイル位置をファイルの先頭からのバイト数で返す。
131 エラーの場合、値 \fI(off_t)\ \-1\fP が返され、
139 .\"O is not an open file descriptor.
141 がオープンされたファイルディスクリプタでない。
149 .\"O or the resulting file offset would be negative,
150 .\"O or beyond the end of a seekable device.
151 .\"O .\" Some systems may allow negative offsets for character devices
152 .\"O .\" and/or for remote file systems.
159 または、seek の結果、ファイル・オフセットが負になってしまうか、
160 seek 可能なデバイスの末尾を越えてしまう。
161 .\" システムによってはキャラクタデバイスやリモートファイルシステムに対して
162 .\" 負のオフセットが許されるかもしれない。
164 .\"O .\" HP-UX 11 says EINVAL for this case (but POSIX.1 says EOVERFLOW)
165 .\"O The resulting file offset cannot be represented in an
167 .\" この場合 HP-UX 11 は EINVAL を返す (一方、POSIX.1 は EOVERFLOW を返す)
174 .\"O is associated with a pipe, socket, or FIFO.
176 がパイプ、ソケット、FIFO を参照している。
178 SVr4, 4.3BSD, POSIX.1-2001.
181 .\"O This document's use of
183 .\"O is incorrect English, but maintained for historical reasons.
189 .\"O Some devices are incapable of seeking and POSIX does not specify which
190 .\"O devices must support
192 いくつかのデバイスでは seek ができない。
199 .\"O on a tty device returns
201 .\"O .\" Other systems return the number of written characters,
202 .\"O .\" using SEEK_SET to set the counter. (Of written characters.)
207 .\" 他のシステムでは書き込まれた文字の数を返し、
208 .\" SEEK_SET を用いてカウンタを設定する。 (書き込まれた文字の。)
210 .\"O When converting old code, substitute values for \fIwhence\fP with the
211 .\"O following macros:
212 古いコードを変換する時は \fIwhence\fP の値を以下のマクロに置き換えること:
225 .\" .\"O SVr1-3 returns \fIlong\fP instead of \fIoff_t\fP,
226 .\" .\"O (ancient) BSD returns \fIint\fP.
227 .\" 返り値の型は、SVr1-3 では \fIoff_t\fP ではなく \fIlong\fP であり、
228 .\" (古い) BSD では \fIint\fP である。
230 .\"O Note that file descriptors created by
234 .\"O share the current file position pointer, so seeking on such files may be
235 .\"O subject to race conditions.
239 で作成されたファイルディスクリプタは、現在のファイル位置ポインタ
240 (current file position pointer) を共有しているので、
241 このようなファイルで移動を行うと競合状態を引き起こす可能性がある。
248 .BR posix_fallocate (3)