4.3BSD-Reno/share/man/cat2/getdirentries.0
GETDIRENTRIES(2) 1990 GETDIRENTRIES(2)
NNAAMMEE
getdirentries - get directory entries in a filesystem
independent format
SSYYNNOOPPSSIISS
##iinncclluuddee <<ssyyss//ddiirreenntt..hh>>
cccc == ggeettddiirreennttrriieess((ffdd,, bbuuff,, nnbbyytteess,, bbaasseepp))
iinntt cccc,, ffdd;;
cchhaarr **bbuuff;;
iinntt nnbbyytteess;;
lloonngg **bbaasseepp;;
DDEESSCCRRIIPPTTIIOONN
_G_e_t_d_i_r_e_n_t_r_i_e_s reads directory entries from the directory
referenced by the file descriptor _f_d into the buffer pointed
to by _b_u_f, in a filesystem independent format. Up to _n_b_y_t_e_s
of data will be transferred. _N_b_y_t_e_s must be greater than or
equal to the block size associated with the file, see
_s_t_a_t(_2). Some filesystems may not support _g_e_t_d_i_r_e_n_t_r_i_e_s
with buffers smaller than this size.
The data in the buffer is a series of _d_i_r_e_n_t structures each
containing the following entries:
unsigned long d_fileno;
unsigned short d_reclen;
unsigned short d_namlen;
char d_name[MAXNAMELEN + 1]; /* see below */
The _d__f_i_l_e_n_o entry is a number which is unique for each dis-
tinct file in the filesystem. Files that are linked by hard
links (see _l_i_n_k(_2)) have the same _d__f_i_l_e_n_o. The _d__r_e_c_l_e_n
entry is the length, in bytes, of the directory record. The
_d__n_a_m_e entry contains a null terminated file name. The
_d__n_a_m_l_e_n entry specifies the length of the file name exclud-
ing the null byte. Thus the actual size of _d__n_a_m_e may vary
from 1 to MMAAXXNNAAMMEELLEENN ++ 11.
Entries may be separated by extra space. The _d__r_e_c_l_e_n entry
may be used as an offset from the start of a _d_i_r_e_n_t struc-
ture to the next structure, if any.
The actual number of bytes transferred is returned. The
current position pointer associated with _f_d is set to point
to the next block of entries. The pointer may not advance
by the number of bytes returned by _g_e_t_d_i_r_e_n_t_r_i_e_s. A value
of zero is returned when the end of the directory has been
reached.
_G_e_t_d_i_r_e_n_t_r_i_e_s writes the position of the block read into the
location pointed to by _b_a_s_e_p. Alternatively, the current
Printed 7/27/90 June 1
GETDIRENTRIES(2) 1990 GETDIRENTRIES(2)
position pointer may be set and retrieved by _l_s_e_e_k(_2). The
current position pointer should only be set to a value
returned by _l_s_e_e_k(_2) , a value returned in the location
pointed to by _b_a_s_e_p , or zero.
RREETTUURRNN VVAALLUUEE
If successful, the number of bytes actually transferred is
returned. Otherwise, a -1 is returned and the global vari-
able _e_r_r_n_o is set to indicate the error.
EERRRROORRSS
_G_e_t_d_i_r_e_n_t_r_i_e_s will fail if one or more of the following are
true:
EBADF _f_d is not a valid file descriptor open for
reading.
EFAULT Either _b_u_f or _b_a_s_e_p point outside the allo-
cated address space.
EIO An I/O error occurred while reading from or
writing to the file system.
SSEEEE AALLSSOO
open(2), lseek(2)
Printed 7/27/90 June 2