Debian Codegraph @

doc/seek.n

raw
1 '\"
2 '\" Copyright (c) 1993 The Regents of the University of California.
3 '\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
4 '\"
5 '\" See the file "license.terms" for information on usage and redistribution
6 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7 '\"
8 .TH seek n 8.1 Tcl "Tcl Built-In Commands"
9 .so man.macros
10 .BS
11 '\" Note: do not modify the .SH NAME line immediately below!
12 .SH NAME
13 seek \- Change the access position for an open channel
14 .SH SYNOPSIS
15 \fBseek \fIchannelId offset \fR?\fIorigin\fR?
16 .BE
17 .SH DESCRIPTION
18 .PP
19 Changes the current access position for \fIchannelId\fR.
20 .PP
21 \fIChannelId\fR must be an identifier for an open channel such as a
22 Tcl standard channel (\fBstdin\fR, \fBstdout\fR, or \fBstderr\fR),
23 the return value from an invocation of \fBopen\fR or \fBsocket\fR, or
24 the result of a channel creation command provided by a Tcl extension.
25 .PP
26 The \fIoffset\fR and \fIorigin\fR
27 arguments specify the position at which the next read or write will occur
28 for \fIchannelId\fR. \fIOffset\fR must be an integer (which may be
29 negative) and \fIorigin\fR must be one of the following:
30 .TP 10
31 \fBstart\fR
32 .
33 The new access position will be \fIoffset\fR bytes from the start
34 of the underlying file or device.
35 .TP 10
36 \fBcurrent\fR
37 .
38 The new access position will be \fIoffset\fR bytes from the current
39 access position; a negative \fIoffset\fR moves the access position
40 backwards in the underlying file or device.
41 .TP 10
42 \fBend\fR
43 .
44 The new access position will be \fIoffset\fR bytes from the end of
45 the file or device. A negative \fIoffset\fR places the access position
46 before the end of file, and a positive \fIoffset\fR places the access
47 position after the end of file.
48 .PP
49 The \fIorigin\fR argument defaults to \fBstart\fR.
50 .PP
51 The command flushes all buffered output for the channel before the command
52 returns, even if the channel is in non-blocking mode.
53 It also discards any buffered and unread input.
54 This command returns an empty string.
55 An error occurs if this command is applied to channels whose underlying
56 file or device does not support seeking.
57 .PP
58 Note that \fIoffset\fR values are byte offsets, not character
59 offsets. Both \fBseek\fR and \fBtell\fR operate in terms of bytes,
60 not characters, unlike \fBread\fR.
61 .SH EXAMPLES
62 .PP
63 Read a file twice:
64 .PP
65 .CS
66 set f [open file.txt]
67 set data1 [read $f]
68 \fBseek\fR $f 0
69 set data2 [read $f]
70 close $f
71 # $data1 eq $data2 if the file wasn't updated
72 .CE
73 .PP
74 Read the last 10 bytes from a file:
75 .PP
76 .CS
77 set f [open file.data]
78 # This is guaranteed to work with binary data but
79 # may fail with other encodings...
80 fconfigure $f -translation binary
81 \fBseek\fR $f -10 end
82 set data [read $f 10]
83 close $f
84 .CE
85 .SH "SEE ALSO"
86 file(n), open(n), close(n), gets(n), tell(n), Tcl_StandardChannels(3)
87 .SH KEYWORDS
88 access position, file, seek
89 '\" Local Variables:
90 '\" mode: nroff
91 '\" fill-column: 78
92 '\" End: