Note: this call behaves like read() - the name stored in buf is not null-terminated.
Which filename is the "next" is chosen based on the seek pointer associated with the file handle. The meaning of the seek pointer on a directory is defined by the filesystem in use and should not be interpreted - the only ways in which lseek should be used are with SEEK_SET and an offset previously returned by lseek, or with any of SEEK_SET, SEEK_CUR, or SEEK_EOF with an offset of 0.
EBADF fd is not a valid file handle. ENOTDIR fd does not refer to a directory. EIO A hard I/O error occurred. EFAULT buf points to an invalid address.