Nios® V Processor Software Developer Handbook

ID 743810
Date 7/08/2024
Public
Document Table of Contents

16.1.1.66. lseek()

Prototype

off_t lseek(int fd, off_t ptr, int whence)

Commonly Called By

C/C++ programs

newlib C library

Thread-safe

See description.

Available from ISR

No.

Include

<unistd.h>

Description

The lseek() function moves the read/write pointer associated with the file descriptor fd. lseek() is wrapper function that passes control directly to the lseek() function registered for the driver associated with the file descriptor. If the driver does not provide an implementation of lseek(), an error is reported.

lseek() corresponds to the standard UNIX lseek() function.

You can use the following values for the input parameter, whence:

  • SEEK_SET—The offset is set to ptr bytes.
  • SEEK_CUR—The offset is incremented by ptr bytes.
  • SEEK_END—The offset is set to the end of the file plus ptr bytes.

    Calls to lseek() are thread-safe only if the implementation of lseek() provided by the driver that is manipulated is thread-safe.

    Valid values for the fd parameter are: stdout, stdin, and stderr, or any value returned from a call to open().

Return

On success, the return value is a nonnegative file pointer. The return value is –1 in the event of an error. If the call fails, errno is set to indicate the cause of the error.