sys_fhseek
Previous Topic  Next Topic 

Synopsis:

        sys_fhseek(file_handle,offet,fromwhere)

Arguments:

        file_handle        - The file handle

        offset                - The byte offset in the file to seek to

        fromwhere         - Where to seek from


Description:    This function moves the current file pointer of the specified file_handle to the byte position in the file specifed by offset.    The fromwhere argument defines where offset is being measured from:


        0        move relative to start of file

        1        move relative to current position

        2        move relative to end of file


A negative value of offset indicates to move the pointer backwards towards the start of the file.      


Return Value


Returns the new file position relative to the start of the file, or a negative error code.



Since the function returns the new position in the file after the move has been carried out, the current file position can be establish by calling the function but by specifying a move of zero bytes from the current position.    The following example uses he sys_fhseek() function to find the length of a file by moving to the last byte.     Once the length has been found it then moves back to the previous position in the file:



     // Get our current position

     curr_pos=sys_fhseek(fhandle,0,1);


     // Move to end of file to find the file size

     file_size=sys_fhseek(fhandle,0,2);


     // Move back to where we started from

     sys_fhseek(fhandle,curr_pos,0);