seek.n
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:3k
- '"
- '" Copyright (c) 1993 The Regents of the University of California.
- '" Copyright (c) 1994-1996 Sun Microsystems, Inc.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: seek.n,v 1.5.8.1 2004/10/27 14:23:58 dkf Exp $
- '"
- .so man.macros
- .TH seek n 8.1 Tcl "Tcl Built-In Commands"
- .BS
- '" Note: do not modify the .SH NAME line immediately below!
- .SH NAME
- seek - Change the access position for an open channel
- .SH SYNOPSIS
- fBseek fIchannelId offset fR?fIoriginfR?
- .BE
- .SH DESCRIPTION
- .PP
- Changes the current access position for fIchannelIdfR.
- .PP
- .VS
- fIChannelIdfR must be an identifier for an open channel such as a
- Tcl standard channel (fBstdinfR, fBstdoutfR, or fBstderrfR),
- the return value from an invocation of fBopenfR or fBsocketfR, or
- the result of a channel creation command provided by a Tcl extension.
- .VE
- .PP
- The fIoffsetfR and fIoriginfR
- arguments specify the position at which the next read or write will occur
- for fIchannelIdfR. fIOffsetfR must be an integer (which may be
- negative) and fIoriginfR must be one of the following:
- .TP 10
- fBstartfR
- The new access position will be fIoffsetfR bytes from the start
- of the underlying file or device.
- .TP 10
- fBcurrentfR
- The new access position will be fIoffsetfR bytes from the current
- access position; a negative fIoffsetfR moves the access position
- backwards in the underlying file or device.
- .TP 10
- fBendfR
- The new access position will be fIoffsetfR bytes from the end of
- the file or device. A negative fIoffsetfR places the access position
- before the end of file, and a positive fIoffsetfR places the access
- position after the end of file.
- .LP
- The fIoriginfR argument defaults to fBstartfR.
- .PP
- The command flushes all buffered output for the channel before the command
- returns, even if the channel is in nonblocking mode.
- It also discards any buffered and unread input.
- This command returns an empty string.
- An error occurs if this command is applied to channels whose underlying
- file or device does not support seeking.
- .PP
- .VS 8.1
- Note that fIoffsetfR values are byte offsets, not character
- offsets. Both fBseekfR and fBtellfR operate in terms of bytes,
- not characters, unlike fBreadfR.
- .VE 8.1
- .SH EXAMPLES
- Read a file twice:
- .CS
- set f [open file.txt]
- set data1 [read $f]
- fBseekfR $f 0
- set data2 [read $f]
- close $f
- # $data1 == $data2 if the file wasn't updated
- .CE
- .PP
- Read the last 10 bytes from a file:
- .CS
- set f [open file.data]
- # This is guaranteed to work with binary data but
- # may fail with other encodings...
- fconfigure $f -translation binary
- fBseekfR $f -10 end
- set data [read $f 10]
- close $f
- .CE
- .SH "SEE ALSO"
- file(n), open(n), close(n), gets(n), tell(n), Tcl_StandardChannels(3)
-
- .SH KEYWORDS
- access position, file, seek