chan seek
Moves the place of the next read or write of a channel.
chan seek CHAN OFFSET ?ORIGIN?
Description
Moves the place of CHAN to OFFSET bytes from ORIGIN: start (the default), current, or end. A negative OFFSET moves back from current or end. A seek empties the buffers of the channel.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| CHAN | channel | required | The channel. |
| OFFSET | integer | required | The count of bytes to move. |
| ORIGIN | start, current, or end | start | The place that OFFSET counts from. Values: |
Returns
An empty string.
Examples
% set f [open a.txt w]; chan puts $f hello; chan close $f
> set f [open a.txt]
> chan seek $f 2
> set d [chan read $f]
> chan close $f
> set d
llo
% set f [open a.txt]
> chan seek $f -2 end
> set d [chan read $f]
> chan close $f
> set d
o
Errors
% set f [open a.txt]
> catch {chan seek $f x} m
> chan close $f
> error $m
expected integer but got "x"
-errorcode NONE
Facts
- Capability
channels. A new interpreter does not have it until the host turns it on.- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1