1 | .\" Copyright (c) 1980 Regents of the University of California.
|
---|
2 | .\" All rights reserved. The Berkeley software License Agreement
|
---|
3 | .\" specifies the terms and conditions for redistribution.
|
---|
4 | .\"
|
---|
5 | .\" @(#)lseek.2 6.3 (Berkeley) 2/24/86
|
---|
6 | .\"
|
---|
7 | .TH LSEEK 2 "February 24, 1986"
|
---|
8 | .UC 4
|
---|
9 | .SH NAME
|
---|
10 | lseek \- move read/write pointer
|
---|
11 | .SH SYNOPSIS
|
---|
12 | .nf
|
---|
13 | .ft B
|
---|
14 | #include <sys/types.h>
|
---|
15 | #include <unistd.h>
|
---|
16 |
|
---|
17 | .ta +1.8i +0.6i
|
---|
18 | #define SEEK_SET 0 /* offset is absolute */
|
---|
19 | #define SEEK_CUR 1 /* relative to current position */
|
---|
20 | #define SEEK_END 2 /* relative to end of file */
|
---|
21 |
|
---|
22 | off_t lseek(int d, off_t offset, int whence)
|
---|
23 | .fi
|
---|
24 | .ft R
|
---|
25 | .SH DESCRIPTION
|
---|
26 | The descriptor
|
---|
27 | .I d
|
---|
28 | refers to a file or device open for reading and/or writing.
|
---|
29 | .B Lseek
|
---|
30 | sets the file pointer of
|
---|
31 | .I d
|
---|
32 | as follows:
|
---|
33 | .IP
|
---|
34 | If
|
---|
35 | .I whence
|
---|
36 | is SEEK_SET, the pointer is set to
|
---|
37 | .I offset
|
---|
38 | bytes.
|
---|
39 | .IP
|
---|
40 | If
|
---|
41 | .I whence
|
---|
42 | is SEEK_CUR, the pointer is set to its current location plus
|
---|
43 | .IR offset .
|
---|
44 | .IP
|
---|
45 | If
|
---|
46 | .I whence
|
---|
47 | is SEEK_END, the pointer is set to the size of the
|
---|
48 | file plus
|
---|
49 | .IR offset .
|
---|
50 | .PP
|
---|
51 | Upon successful completion, the resulting pointer location
|
---|
52 | as measured in bytes from beginning of the file is returned.
|
---|
53 | Some devices are incapable of seeking. The value of the pointer
|
---|
54 | associated with such a device is undefined.
|
---|
55 | .SH NOTES
|
---|
56 | Seeking far beyond the end of a file, then writing,
|
---|
57 | creates a gap or \*(lqhole\*(rq, which occupies no
|
---|
58 | physical space and reads as zeros.
|
---|
59 | .SH "RETURN VALUE
|
---|
60 | Upon successful completion,
|
---|
61 | the current file pointer value is returned.
|
---|
62 | Otherwise,
|
---|
63 | a value of \-1 is returned and \fBerrno\fP is set to indicate
|
---|
64 | the error.
|
---|
65 | .SH "ERRORS
|
---|
66 | .B Lseek
|
---|
67 | will fail and the file pointer will remain unchanged if:
|
---|
68 | .TP 15
|
---|
69 | [EBADF]
|
---|
70 | .I Fildes
|
---|
71 | is not an open file descriptor.
|
---|
72 | .TP 15
|
---|
73 | [ESPIPE]
|
---|
74 | .I Fildes
|
---|
75 | is associated with a pipe or a socket.
|
---|
76 | .TP 15
|
---|
77 | [EINVAL]
|
---|
78 | .I Whence
|
---|
79 | is not a proper value.
|
---|
80 | .SH "SEE ALSO"
|
---|
81 | .BR fcntl (2),
|
---|
82 | .BR open (2).
|
---|
83 | .SH BUGS
|
---|
84 | This document's use of
|
---|
85 | .I whence
|
---|
86 | is incorrect English, but maintained for historical reasons.
|
---|