Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- DOS 5.0 Ref. - <b>function 42h move file pointer (lseek)</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Function 42h            Move File Pointer (LSEEK)

    Moves the file pointer forward or backward in an open file.

        Entry   AH    = 42h
                BX    = File handle
                CX:DX = Offset, in bytes (32-bit integer)
                AL    = Mode code:
                         0   Move file pointer CX:DX bytes from
                             beginning of file (offset = un-signed value)
                         1   Move file pointer CX:DX bytes from
                             current location (offset = signed value)
                         2   Move file pointer CX:DX bytes from
                             end of file (offset = signed value)

        Return  DX:AX = New file position (unsigned 32-bit), from
                        start of file
                or
                AX = Error code, if CF is set
                     | 01h Invalid function (bad mode code)
                     | 06h Invalid handle

    ------------------------------------------------------------------

    This function changes the logical read/write position in the
    specified file, by incrementing or decrementing the value assigned
    to the file pointer. The file pointer is maintained by the system
    and is shared by all file handles that identify a given file.

    With method 00h, the 32-bit value in CX:DX is always interpreted
    as a positive value. 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 action 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, 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, but
    using this method to grow a file from zero bytes to a very large
    size can corrupt the FAT in some versions of DOS; the file should
    first be grown from zero to one byte and then to the desired large
    size.


    Use AL = 2 and CX:DX = 0 to move the file pointer to the end of
    the file, or to find the length of the file.

    A file can be truncated my moving the file pointer to the new end
    of file and writing zero bytes using function 40h.

See Also: 40h 3fh 59h

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson