DIRECTORY(3) 1990 DIRECTORY(3) NNAAMMEE opendir, readdir, telldir, seekdir, rewinddir, closedir, dirfd - directory operations SSYYNNOOPPSSIISS ##iinncclluuddee <<ssyyss//ttyyppeess..hh>> ##iinncclluuddee <<ddiirreenntt..hh>> DDIIRR ** ooppeennddiirr((ccoonnsstt cchhaarr **ffiilleennaammee));; ssttrruucctt ddiirreecctt **rreeaaddddiirr((DDIIRR ** ddiirrpp));; lloonngg tteellllddiirr((ccoonnsstt DDIIRR **ddiirrpp));; vvooiidd sseeeekkddiirr((DDIIRR **ddiirrpp,, lloonngg lloocc));; vvooiidd rreewwiinnddddiirr((DDIIRR **ddiirrpp));; iinntt cclloosseeddiirr((DDIIRR **ddiirrpp));; iinntt ddiirrffdd((DDIIRR **ddiirrpp)) DDEESSCCRRIIPPTTIIOONN _O_p_e_n_d_i_r opens the directory named by _f_i_l_e_n_a_m_e and associates a _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m with it. _O_p_e_n_d_i_r returns a pointer to be used to identify the _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m in subsequent opera- tions. The pointer NNUULLLL is returned if _f_i_l_e_n_a_m_e cannot be accessed, or if it cannot _m_a_l_l_o_c(3) enough memory to hold the whole thing. _R_e_a_d_d_i_r returns a pointer to the next directory entry. It returns NNUULLLL upon reaching the end of the directory or detecting an invalid _s_e_e_k_d_i_r operation. _T_e_l_l_d_i_r returns the current location associated with the named _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m. _S_e_e_k_d_i_r sets the position of the next _r_e_a_d_d_i_r operation on the _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m. The new position reverts to the one associated with the _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m when the _t_e_l_l_d_i_r opera- tion was performed. Values returned by _t_e_l_l_d_i_r are good only for the lifetime of the DIR pointer from which they are derived. If the directory is closed and then reopened, the _t_e_l_l_d_i_r value may be invalidated due to undetected directory compaction. It is safe to use a previous _t_e_l_l_d_i_r value Printed 7/27/90 June 1 DIRECTORY(3) 1990 DIRECTORY(3) immediately after a call to _o_p_e_n_d_i_r and before any calls to _r_e_a_d_d_i_r. _R_e_w_i_n_d_d_i_r resets the position of the named _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m to the beginning of the directory. _C_l_o_s_e_d_i_r closes the named _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m and frees the structure associated with the DIR pointer, returning 0 on success. On failure, -1 is returned and errno is set to indicate the error. _D_i_r_f_d returns the integer file descriptor associated with the named _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m, see open(2). Sample code which searchs a directory for entry ``name'' is: len = strlen(name); dirp = opendir("."); for (dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) if (dp->d_namlen == len && !strcmp(dp->d_name, name)) { (void)closedir(dirp); return FOUND; } (void)closedir(dirp); return NOT_FOUND; SSEEEE AALLSSOO open(2), close(2), read(2), lseek(2), dir(5) Printed 7/27/90 June 2