getdents(3)getdents(3)NAMEgetdents - Reads directory entries and put in a file system independent
format
SYNOPSIS
#include <dirent.h> #include <errno.h>
long getdents(
int filedes, struct dirent *buf, size_t,
nbyte );
LIBRARY
SVR4 Library (libsvr4)
PARAMETERS
Specifies the file descriptor associated with the directory. Specifies
a directory entry structure, which is of variable length. Specifies
the data buffer. Specifies the maximum amount of data to be trans‐
ferred in bytes and is an unsigned long. Specifies the size of the
data buffer.
DESCRIPTION
The getdents() function attempts to read nbyte bytes from the directory
associated with fildes and to format them as file system independent
directory entries in the buffer pointed to by buf. Since the file sys‐
tem independent directory entries are of variable length, in most cases
the actual number of bytes returned will be strictly less than nbyte.
The fildes file descriptor is obtained from an open(2) or dup(2) system
call.
The file system independent directory entry is specified by the dirent
structure.
On devices capable of seeking, getdents() starts at a position in the
file given by the file pointer associated with fildes. Upon return
from getdents() function, the file pointer is incremented to point to
the next directory entry.
This system call was developed in order to implement the readdir rou‐
tine and should not be used for other purposes.
NOTES
Version supports the [Tru64 UNIX] definition of the dirent structure,
which is different from the SVR4 definition. Some of the files that
are referenced by absolute path in the System V Environment for [Tru64
UNIX] reference pages actually may be located relative to
/usr/opt/svr4.
RETURN VALUES
If the getdents() function fails a value of -1 is returned, and errno
is set as shown in the ERRORS section. On success the getdents() func‐
tion returns the number of bytes read.
ERRORS
The fildes descriptor is not a valid file descriptor open for reading.
The buffer buf points to a location outside the allocated address space
of the process. The nbyte size is not large enough for one directory
entry. The current file pointer for the directory is not located at a
valid entry. The fildes descriptor is not a directory. An I/O error
occurred while accessing the file system.
SEE ALSO
Functions: getdirentries(2), open(2), lseek(2)getdents(3)