fseek()
Set the file position indicator.
Syntax
Parameter
Parameter | Definition |
---|---|
channel | file I/O channel returned when the file was opened by the fopen() function |
offset | number of bytes to be added to whence to obtain the file position |
whence | standard point within a file to which the offset is added to obtain the new file position*Valid Values* |
Description
The fseek() function sets the filename position indicator to the whence position plus offset bytes.
When the fseek() function encounters invalid parameters (either the whence, offset, or both ), the invalid parameters default to zero, and the fseek() function raises a run-time error and completes the file seek operation. Normally, after an invalid parameter defaults to zero, the fseek() function completes successfully.
The fseek() function returns 0 for success and -1 for failure. For an invalid channel, such as a pipe channel or a socket channel instead of a file channel, the fseek() function returns -1, raises a run-time error, and sets the PSL errno variable.
fseek and Append File Mode
Using the fseek() function to change the file position indicator in a file opened in append mode, that is, modes a, ab, ora+, will not prevent writes to the end of the file using the write() function.
Microsoft Windows Has Limited Support for fseek()
On Microsoft Windows, you cannot use fseek when whence is 1 or with a file that has been opened in text mode. Using fseek under these conditions sets the PSL errno variable to the following value:
Numeric Value | Message |
---|---|
138 | E_PSL_RTE_FSEEK_RESTRICTED_FILEOPEN_MODE |
PATROL also displays the following error message in the system output window:
Text mode fseek is not supported. Refer to the PATROL Script Language Reference Manual.
Example
PSL contains no equivalent to the C rewind() function, but the following fseek() function example is the equivalent of the C function rewind(channel):
The following fseek() function moves the file position indicator 100 bytes past its current location: