Important

   

This documentation space contains information about PATROL Agents when deployed in a TrueSight Operations Management environment. If you are a BMC Helix Operations Management user, see PATROL Agent 22.1 for BMC Helix Operations Management. Open link

fseek()

Set the file position indicator.

Syntax

fseek(channel,offset,whence)

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* 
0 beginning of the file 
1 current file position 
2 end of the file

Note

 Issuing the fseek() function against binary files with whence = 2 is not supported on all platforms. See also Microsoft Windows Has Limited Support for fseek().

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 whenceoffset, 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 aab, 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):

fseek(channel,0,0);

The following fseek() function moves the file position indicator 100 bytes past its current location:

fseek(chan,100,1);
Was this page helpful? Yes No Submitting... Thank you

Comments