DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

getdents(S)


getdents -- read directory entries and put in a file system independent format

Synopsis

   #include <sys/types.h>
   #include <sys/dirent.h>
   

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

Description

fildes is a file descriptor obtained from a creat, open, dup, fcntl, pipe, or ioctl system call.

getdents 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 system independent directory entries are of variable length, in most cases the actual number of bytes returned will be strictly less than nbyte. See dirent(F) to calculate the number of bytes.

The file system independent directory entry is specified by the dirent structure. For a description of this see dirent(F).

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, the file pointer is incremented to point to the next directory entry.

This system call was developed in order to implement the readdir routine (for a description, see directory(S)), and should not be used for other purposes.

Return values

On success, getdents returns a non-negative integer indicating the number of bytes actually read, or 0 if the end of the directory has been reached. On failure, getdents returns -1 and sets errno to identify the error.

In the following conditions, getdents fails and sets errno to:


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

EFAULT
buf points outside the allocated address space.

EINVAL
nbyte is not large enough for one directory entry.

ENOENT
The current file pointer for the directory is not located at a valid entry.

ENOLINK
fildes points to a remote machine and the link to that machine is no longer active.

ENOTDIR
fildes is not a directory.

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

References

directory(S), dirent(F)
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 - 01 June 2005