Function 42h Move File Pointer

mov bx, Handle ;file handle

mov cx, HiOffset ;most-significant 16 bits of offset

mov dx, LoOffset ;least-significant 16 bits of offset

mov al, MoveMethod ;move method code

or ah, 42h ;Move File Pointer

int 21h

jc error_handler ;carry set means error

mov HiPosition, dx ;high 16 bits of absolute position

mov LoPosition, ax ;low 16 bits of absolute position

Move File Pointer (Function 42h) moves the file pointer to the specified position in the file. The file pointer is maintained by the system; it points to the next byte to be read from a file or to the next position in the file to receive a byte.

Parameters

Handle

Identifies an open file.

HiOffset

Specifies the most-significant 16 bits of a 32-bit offset. The offset specifies the number of bytes to move the file pointer. This value may be positive or negative.

LoOffset

Specifies the least-significant 16 bits of the 32-bit offset.

MoveMethod

Specifies where the move will start. This parameter must be one of the following values:

Value Meaning

00h Start move at the beginning of the file.
01h Start move at the current location.
02h Start move at the end of the file.

Return Value

If the function is successful, the carry flag is clear and the DX and AX registers contain the new file-pointer position. The DX register contains the most-significant 16 bits of the 32-bit offset, and the AX register contains the least-significant 16 bits. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following values:

Value Name

0001h ERROR_INVALID_FUNCTION
0006h ERROR_INVALID_HANDLE

Comments

This function returns 0001h (ERROR_INVALID_FUNCTION) if a method other than 00h, 01h, or 02h is specified for MoveMethod.

With method 00h, the 32-bit value in the CX and DX registers is always interpreted as a positive value. It is not possible to move the file pointer to a position before the start of the file with method 00h. With methods 01h and 02h, however, the 32-bit offset is interpreted as a signed value; it is possible to move the file pointer either forward or backward.

A program should never attempt to move the file pointer to a position before the start of the file. Although this does not generate an error during the move, it does generate an error on a subsequent read or write operation. A program can move the file pointer beyond the end of the file. On a subsequent write operation, MS-DOS writes data to the given position in the file, filling the gap between the previous end of the file and the given position with undefined data. This is a common way to reserve file space without writing to the file.

See Also

Function 3Fh Read File or Device
Function 40h Write File or Device