GETDIRENTRIES(2) BSD Programmer's Manual GETDIRENTRIES(2) NNAAMMEE ggeettddiirreennttrriieess - get directory entries in a filesystem independent format SSYYNNOOPPSSIISS ##iinncclluuddee <<ssyyss//ddiirreenntt..hh>> _i_n_t ggeettddiirreennttrriieess(_i_n_t _f_d, _c_h_a_r _*_b_u_f, _i_n_t _n_b_y_t_e_s, _l_o_n_g _*_b_a_s_e_p); DDEESSCCRRIIPPTTIIOONN GGeettddiirreennttrriieess() 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 stat(2). Some filesystems may not support ggeettddiirreennttrriieess() 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 distinct file in the filesystem. Files that are linked by hard links (see link(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 di- rectory 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 excluding the null byte. Thus the actual size of _d___n_a_m_e may vary from 1 to MAXNAMELEN + 1. 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 structure 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 ggeettddiirreennttrriieess(). A value of zero is returned when the end of the direc- tory has been reached. GGeettddiirreennttrriieess() writes the position of the block read into the location pointed to by _b_a_s_e_p. Alternatively, the current position pointer may be set and retrieved by lseek(2). The current position pointer should only be set to a value returned by lseek(2), a value returned in the location pointed to by _b_a_s_e_p, or zero. RREETTUURRNN VVAALLUUEESS If successful, the number of bytes actually transferred is returned. Otherwise, -1 is returned and the global variable _e_r_r_n_o is set to indi- cate the error. EERRRROORRSS GGeettddiirreennttrriieess() will fail if: 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 allocated address space. EIO An I/O error occurred while reading from or writing to the file system. SSEEEE AALLSSOO open(2), lseek(2) HHIISSTTOORRYY The ggeettddiirreennttrriieess function first appeared in 4.4BSD. 4.4BSD June 9, 1993 2