| [25] | 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 | 
|---|
 | 15 | seek \- 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 | 
|---|
 | 22 | Changes the current access position for \fIchannelId\fR. | 
|---|
 | 23 | .PP | 
|---|
 | 24 | \fIChannelId\fR must be an identifier for an open channel such as a | 
|---|
 | 25 | Tcl standard channel (\fBstdin\fR, \fBstdout\fR, or \fBstderr\fR), | 
|---|
 | 26 | the return value from an invocation of \fBopen\fR or \fBsocket\fR, or | 
|---|
 | 27 | the result of a channel creation command provided by a Tcl extension. | 
|---|
 | 28 | .PP | 
|---|
 | 29 | The \fIoffset\fR and \fIorigin\fR | 
|---|
 | 30 | arguments specify the position at which the next read or write will occur | 
|---|
 | 31 | for \fIchannelId\fR. \fIOffset\fR must be an integer (which may be | 
|---|
 | 32 | negative) and \fIorigin\fR must be one of the following: | 
|---|
 | 33 | .TP 10 | 
|---|
 | 34 | \fBstart\fR | 
|---|
 | 35 | The new access position will be \fIoffset\fR bytes from the start | 
|---|
 | 36 | of the underlying file or device. | 
|---|
 | 37 | .TP 10 | 
|---|
 | 38 | \fBcurrent\fR | 
|---|
 | 39 | The new access position will be \fIoffset\fR bytes from the current | 
|---|
 | 40 | access position; a negative \fIoffset\fR moves the access position | 
|---|
 | 41 | backwards in the underlying file or device. | 
|---|
 | 42 | .TP 10 | 
|---|
 | 43 | \fBend\fR | 
|---|
 | 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 | .LP | 
|---|
 | 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 nonblocking 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 | Read a file twice: | 
|---|
 | 63 | .CS | 
|---|
 | 64 | set f [open file.txt] | 
|---|
 | 65 | set data1 [read $f] | 
|---|
 | 66 | \fBseek\fR $f 0 | 
|---|
 | 67 | set data2 [read $f] | 
|---|
 | 68 | close $f | 
|---|
 | 69 | # $data1 == $data2 if the file wasn't updated | 
|---|
 | 70 | .CE | 
|---|
 | 71 | .PP | 
|---|
 | 72 | Read the last 10 bytes from a file: | 
|---|
 | 73 | .CS | 
|---|
 | 74 | set f [open file.data] | 
|---|
 | 75 | # This is guaranteed to work with binary data but | 
|---|
 | 76 | # may fail with other encodings... | 
|---|
 | 77 | fconfigure $f -translation binary | 
|---|
 | 78 | \fBseek\fR $f -10 end | 
|---|
 | 79 | set data [read $f 10] | 
|---|
 | 80 | close $f | 
|---|
 | 81 | .CE | 
|---|
 | 82 |  | 
|---|
 | 83 | .SH "SEE ALSO" | 
|---|
 | 84 | file(n), open(n), close(n), gets(n), tell(n), Tcl_StandardChannels(3) | 
|---|
 | 85 |   | 
|---|
 | 86 | .SH KEYWORDS | 
|---|
 | 87 | access position, file, seek | 
|---|