Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/seek.n @ 25

Last change on this file since 25 was 25, checked in by landauf, 16 years ago

added tcl to libs

File size: 2.8 KB
Line 
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'\" RCS: @(#) $Id: seek.n,v 1.9 2005/05/10 18:34:03 kennykb Exp $
9'\"
10.so man.macros
11.TH seek n 8.1 Tcl "Tcl Built-In Commands"
12.BS
13'\" Note:  do not modify the .SH NAME line immediately below!
14.SH NAME
15seek \- Change the access position for an open channel
16.SH SYNOPSIS
17\fBseek \fIchannelId offset \fR?\fIorigin\fR?
18.BE
19
20.SH DESCRIPTION
21.PP
22Changes the current access position for \fIchannelId\fR.
23.PP
24\fIChannelId\fR must be an identifier for an open channel such as a
25Tcl standard channel (\fBstdin\fR, \fBstdout\fR, or \fBstderr\fR),
26the return value from an invocation of \fBopen\fR or \fBsocket\fR, or
27the result of a channel creation command provided by a Tcl extension.
28.PP
29The \fIoffset\fR and \fIorigin\fR
30arguments specify the position at which the next read or write will occur
31for \fIchannelId\fR. \fIOffset\fR must be an integer (which may be
32negative) and \fIorigin\fR must be one of the following:
33.TP 10
34\fBstart\fR
35The new access position will be \fIoffset\fR bytes from the start
36of the underlying file or device.
37.TP 10
38\fBcurrent\fR
39The new access position will be \fIoffset\fR bytes from the current
40access position; a negative \fIoffset\fR moves the access position
41backwards in the underlying file or device.
42.TP 10
43\fBend\fR
44The new access position will be \fIoffset\fR bytes from the end of
45the file or device.  A negative \fIoffset\fR places the access position
46before the end of file, and a positive \fIoffset\fR places the access
47position after the end of file.
48.LP
49The \fIorigin\fR argument defaults to \fBstart\fR.
50.PP
51The command flushes all buffered output for the channel before the command
52returns, even if the channel is in nonblocking mode.
53It also discards any buffered and unread input.
54This command returns an empty string.
55An error occurs if this command is applied to channels whose underlying
56file or device does not support seeking.
57.PP
58Note that \fIoffset\fR values are byte offsets, not character
59offsets.  Both \fBseek\fR and \fBtell\fR operate in terms of bytes,
60not characters, unlike \fBread\fR.
61.SH EXAMPLES
62Read a file twice:
63.CS
64set f [open file.txt]
65set data1 [read $f]
66\fBseek\fR $f 0
67set data2 [read $f]
68close $f
69# $data1 == $data2 if the file wasn't updated
70.CE
71.PP
72Read the last 10 bytes from a file:
73.CS
74set f [open file.data]
75# This is guaranteed to work with binary data but
76# may fail with other encodings...
77fconfigure $f -translation binary
78\fBseek\fR $f -10 end
79set data [read $f 10]
80close $f
81.CE
82
83.SH "SEE ALSO"
84file(n), open(n), close(n), gets(n), tell(n), Tcl_StandardChannels(3)
85 
86.SH KEYWORDS
87access position, file, seek
Note: See TracBrowser for help on using the repository browser.