## getdirentry

#### OS/161 Reference Manual

### Name

getdirentry - read filename from directory

### Library

Standard C Library (libc, -lc)

### Synopsis

#include <unistd.h>
int
getdirentry(int fd, char *buf, size_t buflen);

### Description

getdirentry retrieves the next filename from a directory referred to by the file handle filehandle. The name is stored in buf, an area of size buflen. The length of of the name actually found is returned.

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.

### Return Values

On success, getdirentry returns the length of the name transferred. On error, -1 is returned, and errno is set according to the error encountered.

### Errors

> 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.