Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

getdents - convert directory entries

&pagelevel(4)&pagelevel

Name

Syntax

getdents, getdents64

#include <sys/dirent.h>

int getdents(int fildes, struct dirent *buf, size_t nbyte);
int getdents64(int fildes, struct dirent64 *buf, size_t nbyte); 

Description

fildes is a file descriptor that is returned by a open() or dup() system call.
getdents() attempts to read nbyte bytes from the directly associated with fildes and to
place them in the buffer pointed to by buf as directory entries independent of the file system.
Since the directory entries independent of the file system have different lengths, the actual
number of bytes returned is much smaller than nbyte in most cases.

You look in dirent() (Reference Manual for System Administrators) to calculate the
number of bytes.
The file system independent directory entries are specified using the dirent structure.
You will find a description in dirent().
For devices that can position, getdents() starts at the location in the file that is specified
by the read/write pointer assigned to fildes. After returning from getdents(), the read/write
pointer is incremented so that it points to the next directory entry. This system call was
developed to implement the readdir() function (You will find a description in
directory()) and should therefore not be used for any other purpose.

There is no difference in functionality between getdents() and getdents64() except
that for getdents64() buf points to a dirent64 structure.

Errors

The following descriptions of the error codes depend on the function. You will find a generally
applicable description in intro_prm2() and in errno().

getdents() and getdents64() are unsuccessful if one or more of the following arise:

 

EBADF

EFAULT

EINVAL

ENOENT

fildes is not a open and valid file descriptor for reading.

buf points beyond the assigned address space.

nbyte is not large enough for a directory entry.

The current read/write pointer for the directory does not point to a valid
entry.

 

ENOLINK

fildes points to a remote computer and the connection to this computer is
not active anymore.

 

ENOTDIR

EIO

fildes is not a directory.

An I/O error occurred while accessing the file system.

Return val.

After successful completion, a non-negative integer that specifies the actual number of

bytes read is returned. A return value of 0 means that the end of the
directory was reached. If the system call failed, then -1 is returned and
errno is set to indicate the error. 

See also

directory(), dirent().