OSDN Git Service

Import translated manuals from JM CVS Repository.
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man2 / lseek.2
1 .\" Copyright (c) 1980, 1991 Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
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.
19 .\"
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
30 .\" SUCH DAMAGE.
31 .\"
32 .\"     @(#)lseek.2     6.5 (Berkeley) 3/10/91
33 .\"
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>
40 .\"
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
49 .\"
50 .\"WORD:        end-of-file             ¥Õ¥¡¥¤¥ë¤Î½ªÃ¼(end-of-file)
51 .\"
52 .TH LSEEK 2 2001-09-24 "Linux" "Linux Programmer's Manual"
53 .SH Ì¾Á°
54 lseek \- ¥Õ¥¡¥¤¥ë¤ÎÆɤ߽ñ¤­¥ª¥Õ¥»¥Ã¥È¤Î°ÌÃÖ¤òÊѤ¨¤ë
55 .SH ½ñ¼°
56 .B #include <sys/types.h>
57 .br
58 .B #include <unistd.h>
59 .sp
60 .BI "off_t lseek(int " fd ", off_t " offset ", int " whence );
61 .SH ÀâÌÀ
62 .\"O The
63 .\"O .BR lseek ()
64 .\"O function repositions the offset of the open file associated with the
65 .\"O file descriptor
66 .\"O .I fd
67 .\"O to the argument
68 .\"O .I offset
69 .\"O according to the directive
70 .\"O .I whence
71 .\"O as follows:
72 .BR lseek ()
73 ´Ø¿ô¤Ï¡¢¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿ (descriptor)
74 .I fd
75 ¤ËÂбþ¤¹¤ë¥ª¡¼¥×¥ó¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤Î¥ª¥Õ¥»¥Ã¥È¤ò¡¢
76 .IR  whence
77 ¤Ë´ð¤Å¤­
78 .I offset
79 °ú¤­¿ô¤Î°ÌÃ֤ذʲ¼¤Î¤è¤¦¤ËÊѹ¹¤¹¤ë:
80 .TP
81 .B SEEK_SET
82 .\"O The offset is set to
83 .\"O .I offset
84 .\"O bytes.
85 ¥ª¥Õ¥»¥Ã¥È¤Ï
86 .I offset
87 ¥Ð¥¤¥È¤ËÀßÄꤵ¤ì¤ë¡£
88 .TP
89 .B SEEK_CUR
90 .\"O The offset is set to its current location plus
91 .\"O .I offset
92 .\"O bytes.
93 ¥ª¥Õ¥»¥Ã¥È¤Ï¸½ºß°ÌÃÖ¤Ë
94 .I offset
95 ¥Ð¥¤¥È¤ò­¤·¤¿°ÌÃ֤ˤʤ롣
96 .TP
97 .B SEEK_END
98 .\"O The offset is set to the size of the file plus
99 .\"O .I offset
100 .\"O bytes.
101 ¥ª¥Õ¥»¥Ã¥È¤Ï¥Õ¥¡¥¤¥ë¤Î¥µ¥¤¥º¤Ë
102 .I offset
103 ¥Ð¥¤¥È¤ò­¤·¤¿°ÌÃ֤ˤʤ롣
104 .PP
105 .\"O The
106 .\"O .BR lseek ()
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.
112 .BR lseek ()
113 ´Ø¿ô¤Ï¡¢¥ª¥Õ¥»¥Ã¥È¤ò¥Õ¥¡¥¤¥ë¤ÎËöÈø¤ò±Û¤¨¤¿°ÌÃÖ¤ËÀßÄê¤Ç¤­¤ë
114 (⤷¡¢¤³¤ì¤Ë¤è¤ê¥Õ¥¡¥¤¥ë¤Î¥µ¥¤¥º¤¬ÊѤï¤é¤Ê¤¤)¡£
115 ¤â¤·¥Ç¡¼¥¿¤¬¤³¤Î¥ª¥Õ¥»¥Ã¥È°ÌÃְʹߤ˽ñ¤­¹þ¤Þ¤ì¤¿¾ì¹ç¡¢
116 ´Ö¤Î¶õ·ä¤ÎÉôʬ ("·ê (hole)") ¤ÎÆɤ߽Ф·¤¬¤¢¤ë¤È¡¢
117 ¼ÂºÝ¤Ë¤½¤³¤Ë¥Ç¡¼¥¿¤ò½ñ¤­¹þ¤Þ¤ì¤ë¤Þ¤Ç¤Ï
118 NULL ¥Ð¥¤¥È (\(aq\\0\(aq) ¤ÎÎó¤¬ÊÖ¤µ¤ì¤ë¡£
119 .\"O .SH "RETURN VALUE"
120 .SH ÊÖ¤êÃÍ
121 .\"O Upon successful completion,
122 .\"O .BR lseek ()
123 .\"O returns the resulting offset location as measured in bytes from the
124 .\"O beginning of the file.
125 .\"O Otherwise, a value of \fI(off_t)\ \-1\fP is returned and
126 .\"O .I errno
127 .\"O is set to indicate the error.
128 À®¸ù¤·¤¿¾ì¹ç¡¢
129 .BR lseek ()
130 ¤Ï·ë²Ì¤Î¥Õ¥¡¥¤¥ë°ÌÃÖ¤ò¥Õ¥¡¥¤¥ë¤ÎÀèƬ¤«¤é¤Î¥Ð¥¤¥È¿ô¤ÇÊÖ¤¹¡£
131 ¥¨¥é¡¼¤Î¾ì¹ç¡¢ÃͤȤ·¤Æ \fI(off_t)\ \-1\fP ¤òÊÖ¤·¡¢
132 .I errno
133 ¤Ë¥¨¥é¡¼¤¬»Ø¼¨¤µ¤ì¤ë¡£
134 .\"O .SH ERRORS
135 .SH ¥¨¥é¡¼
136 .TP
137 .B EBADF
138 .\"O .I fd
139 .\"O is not an open file descriptor.
140 .I fd
141 ¤¬¥ª¡¼¥×¥ó¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ç¤Ê¤¤¡£
142 .TP
143 .B EINVAL
144 .\"O .I whence
145 .\"O is not one of
146 .\"O .BR SEEK_SET ,
147 .\"O .BR SEEK_CUR ,
148 .\"O .BR SEEK_END ;
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.
153 .I whence
154 ¤¬
155 .BR SEEK_SET ,
156 .BR SEEK_CUR ,
157 .B SEEK_END
158 ¤Î¤É¤ì¤Ç¤â¤Ê¤¤¡£
159 ¤Þ¤¿¤Ï¡¢seek ¤Î·ë²Ì¡¢¥Õ¥¡¥¤¥ë¡¦¥ª¥Õ¥»¥Ã¥È¤¬Éé¤Ë¤Ê¤Ã¤Æ¤·¤Þ¤¦¤«¡¢
160 seek ²Äǽ¤Ê¥Ç¥Ð¥¤¥¹¤ÎËöÈø¤ò±Û¤¨¤Æ¤·¤Þ¤¦¡£
161 .\" ¥·¥¹¥Æ¥à¤Ë¤è¤Ã¤Æ¤Ï¥­¥ã¥é¥¯¥¿¥Ç¥Ð¥¤¥¹¤ä¥ê¥â¡¼¥È¥Õ¥¡¥¤¥ë¥·¥¹¥Æ¥à¤ËÂФ·¤Æ
162 .\" Éé¤Î¥ª¥Õ¥»¥Ã¥È¤¬µö¤µ¤ì¤ë¤«¤â¤·¤ì¤Ê¤¤¡£
163 .B EOVERFLOW
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
166 .\"O .IR off_t .
167 .\" ¤³¤Î¾ì¹ç HP-UX 11 ¤Ï EINVAL ¤òÊÖ¤¹ (°ìÊý¡¢POSIX.1 ¤Ï EOVERFLOW ¤òÊÖ¤¹)
168 ·ë²Ì¤Î¥Õ¥¡¥¤¥ë¡¦¥ª¥Õ¥»¥Ã¥È¤ò
169 .I off_t
170 ·¿¤Çɽ¸½¤¹¤ë¤³¤È¤¬¤Ç¤­¤Ê¤¤¡£
171 .TP
172 .B ESPIPE
173 .\"O .I fd
174 .\"O is associated with a pipe, socket, or FIFO.
175 .I fd
176 ¤¬¥Ñ¥¤¥×¡¢¥½¥±¥Ã¥È¡¢FIFO ¤ò»²¾È¤·¤Æ¤¤¤ë¡£
177 .SH ½àµò
178 SVr4, 4.3BSD, POSIX.1-2001.
179 .\"O .SH NOTES
180 .SH Ãí°Õ
181 .\"O This document's use of
182 .\"O .I whence
183 .\"O is incorrect English, but maintained for historical reasons.
184 ¤³¤Îʸ¾Ï¤Ç»ÈÍѤ·¤¿
185 .I whence
186 ¤Ï±Ñ¸ì¤È¤·¤ÆÀµ¤·¤¯¤Ê¤¤¤¬¡¢
187 Îò»ËŪÍýͳ¤Ë¤è¤ê¤½¤Î¤Þ¤Þ»È¤ï¤ì¤Æ¤¤¤ë¡£
188
189 .\"O Some devices are incapable of seeking and POSIX does not specify which
190 .\"O devices must support
191 .\"O .BR lseek ().
192 ¤¤¤¯¤Ä¤«¤Î¥Ç¥Ð¥¤¥¹¤Ç¤Ï seek ¤¬¤Ç¤­¤Ê¤¤¡£
193 POSIX ¤Ï¤É¤Î¥Ç¥Ð¥¤¥¹¤¬
194 .BR lseek ()
195 ¤ËÂбþ¤¹¤Ù¤­¤«¤Ïµ¬Äꤷ¤Æ¤¤¤Ê¤¤¡£
196
197 .\"O On Linux, using
198 .\"O .BR lseek ()
199 .\"O on a tty device returns
200 .\"O \fBESPIPE\fP.
201 .\"O .\" Other systems return the number of written characters,
202 .\"O .\" using SEEK_SET to set the counter. (Of written characters.)
203 Linux ¤Ç¤Ï¡¢ tty ¥Ç¥Ð¥¤¥¹¤Ë
204 .BR lseek ()
205 ¤ò»ÈÍѤ¹¤ë¤È
206 \fBESPIPE\fP ¤òÊÖ¤¹¡£
207 .\" Â¾¤Î¥·¥¹¥Æ¥à¤Ç¤Ï½ñ¤­¹þ¤Þ¤ì¤¿Ê¸»ú¤Î¿ô¤òÊÖ¤·¡¢
208 .\" SEEK_SET ¤òÍѤ¤¤Æ¥«¥¦¥ó¥¿¤òÀßÄꤹ¤ë¡£ (½ñ¤­¹þ¤Þ¤ì¤¿Ê¸»ú¤Î¡£)
209
210 .\"O When converting old code, substitute values for \fIwhence\fP with the
211 .\"O following macros:
212 ¸Å¤¤¥³¡¼¥É¤òÊÑ´¹¤¹¤ë»þ¤Ï \fIwhence\fP ¤ÎÃͤò°Ê²¼¤Î¥Þ¥¯¥í¤ËÃÖ¤­´¹¤¨¤ë¤³¤È:
213 .TS
214 c c
215 l l.
216 old     new
217 0       SEEK_SET
218 1       SEEK_CUR
219 2       SEEK_END
220 L_SET   SEEK_SET
221 L_INCR  SEEK_CUR
222 L_XTND  SEEK_END
223 .TE
224 .PP
225 .\"O SVr1-3 returns \fIlong\fP instead of \fIoff_t\fP, BSD returns \fIint\fP.
226 ÊÖ¤êÃͤη¿¤Ï¡¢SVr1-3 ¤Ç¤Ï \fIoff_t\fP ¤Ç¤Ï¤Ê¤¯ \fIlong\fP ¤Ç¤¢¤ê¡¢
227 BSD ¤Ç¤Ï \fIint\fP ¤Ç¤¢¤ë¡£
228 .PP
229 .\"O Note that file descriptors created by
230 .\"O .BR dup (2)
231 .\"O or
232 .\"O .BR fork (2)
233 .\"O share the current file position pointer, so seeking on such files may be
234 .\"O subject to race conditions.
235 .BR dup (2)
236 ¤ä
237 .BR fork (2)
238 ¤ÇºîÀ®¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¥Ç¥£¥¹¥¯¥ê¥×¥¿¤Ï¡¢¸½ºß¤Î¥Õ¥¡¥¤¥ë°ÌÃ֥ݥ¤¥ó¥¿
239 (current file position pointer) ¤ò¶¦Í­¤·¤Æ¤¤¤ë¤Î¤Ç¡¢
240 ¤³¤Î¤è¤¦¤Ê¥Õ¥¡¥¤¥ë¤Ç°ÜÆ°¤ò¹Ô¤¦¤È¶¥¹ç¾õÂÖ¤ò°ú¤­µ¯¤³¤¹²ÄǽÀ­¤¬¤¢¤ë¡£
241 .SH ´ØÏ¢¹àÌÜ
242 .BR dup (2),
243 .BR fork (2),
244 .BR open (2),
245 .BR fseek (3),
246 .BR lseek64 (3),
247 .BR posix_fallocate (3)