weir reddir_r on solaris.
| From: | thies at digicol dot de | Date: | Wed, 07 Jun 2000 14:05:15 +0000 |
| Subject: | weir reddir_r on solaris. | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-20467@lists.php.net to get a copy of this message | ||
sascha,
current php_readdir_r fails on solaris (2.6).
(attached "man readdir_r")
struct dirent *readdir_r(DIR *dirp, struct dirent *entry);
question: didn't we used to compile with tread-save flags
"all-the-time". that would mean we could get the POSIX
readdir_r on solaris, but because we don't configure with
"-D_POSIX_PTHREAD_SEMANTICS" we get the old, broken version.
hmm,
tc
--
Thies C. Arntzen "One Big-Mac, Small Fries and a Coke!"
Digital Collections Phone +49 40 235350 Fax +49 40 23535180
Hammerbrookstr. 93 20097 Hamburg / Germany
C Library Functions readdir(3C) NAME readdir, readdir_r - read directory SYNOPSIS #include <sys/types.h> #include <dirent.h> struct dirent *readdir(DIR *_d_i_r_p); struct dirent *readdir_r(DIR *_d_i_r_p, struct dirent *_e_n_t_r_y); POSIX cc [ _f_l_a_g ... ] _f_i_l_e ... -D_POSIX_PTHREAD_SEMANTICS [ _l_i_b_r_a_r_y ... ] int *readdir_r(DIR *_d_i_r_p, struct dirent *_e_n_t_r_y, struct dirent **_r_e_s_u_l_t); DESCRIPTION The type DIR, which is defined in the header <dirent.h>, represents a _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m, which is an ordered sequence of all the directory entries in a particular directory. Directory entries represent files; files may be removed from a directory or added to a directory asynchronously to the operation of readdir() and readdir_r(). readdir() The readdir() function returns a pointer to a structure representing the directory entry at the current position in the directory stream specified by the argument _d_i_r_p, and positions the directory stream at the next entry. It returns a null pointer upon reaching the end of the direc- tory stream. The structure dirent defined by the <dirent.h> header describes a directory entry. If entries for dot or dot-dot exist, one entry will be returned for dot and one entry will be returned for dot-dot; otherwise they will not be returned. The pointer returned by readdir() points to data which may be overwritten by another call to readdir() on the same directory stream. This data is not overwritten by another call to readdir() on a different directory stream. If a file is removed from or added to the directory after the most recent call to opendir(3C) or rewinddir(3C), whether a subsequent call to readdir() returns an entry for that file is unspecified. The readdir() function may buffer several directory entries per actual read operation; readdir() marks for update the _s_t__a_t_i_m_e field of the directory each time the directory is SunOS 5.6 Last change: 20 Mar 1997 1 C Library Functions readdir(3C) actually read. After a call to fork(2), either the parent or child (but not both) may continue processing the directory stream using readdir(), rewinddir() or seekdir(3C). If both the parent and child processes use these functions, the result is unde- fined. If the entry names a symbolic link, the value of the d_ino member is unspecified. readdir_r() The readdir_r() function is equivalent to readdir() except that a buffer _r_e_s_u_l_t must be supplied by the caller to store the result. The size should be sizeof(struct dirent) + {NAME_MAX} (that is, pathconf(_PC_NAME_MAX)) + 1. _PC_NAME_MAX is defined in <unistd.h>. The POSIX version (see standards(5)) of the readdir_r() function initializes the structure referenced by _e_n_t_r_y and stores a pointer to this structure in _r_e_s_u_l_t. RETURN VALUES Upon successful completion, readdir() and readdir_r() return a pointer to an object of type struct dirent. When an error is encountered, a null pointer is returned and errno is set to indicate the error. When the end of the directory is encountered, a null pointer is returned and errno is not changed. The POSIX readdir_r() returns 0 if successful or an error number to indicate failure. ERRORS The readdir() function will fail if: EOVERFLOW One of the values in the structure to be returned cannot be represented correctly. The readdir() and readdir_r() functions will fail if: EBADF The file descriptor determined by the DIR stream is no longer valid. This results if the DIR stream has been closed. ENOENT The current file pointer for the directory is not located at a valid entry. The readdir() and readdir_r() functions may fail if: EBADF The _d_i_r_p argument does not refer to an open directory stream. ENOENT The current position of the directory stream SunOS 5.6 Last change: 20 Mar 1997 2 C Library Functions readdir(3C) is invalid. USAGE The readdir() function should be used in conjunction with opendir(), closedir(), and rewinddir() to examine the con- tents of the directory. As readdir() returns a null pointer both at the end of the directory and on error, an applica- tion wishing to check for error situations should set errno to 0, then call readdir(), then check errno and if it is non-zero, assume an error has occurred. The readdir() and readdir_r() functions have explicit 64-bit equivalents. See interface64(5). EXAMPLES The following sample code will search the current directory for the entry _n_a_m_e: dirp = opendir("."); while ((dp = readdir(dirp)) != NULL) if (strcmp(dp->d_name, name) == 0) { closedir(dirp); return FOUND; } closedir(dirp); return NOT_FOUND; ATTRIBUTES See attributes(5) for descriptions of the following attri- butes: ___________________________________ | ATTRIBUTE TYPE| ATTRIBUTE VALUE | |_______________________________|______________________________________|_ | MT-Level | See NOTES below.| |________________|___________________| SEE ALSO fork(2), lstat(2), symlink(2), Intro(3), closedir(3C), opendir(3C), rewinddir(3C), seekdir(3C), attributes(5), interface64(5), standards(5) NOTES When compiling multithread programs, see Intro(3), _N_o_t_e_s _O_n _M_u_l_t_i_t_h_r_e_a_d _A_p_p_l_i_c_a_t_i_o_n_s. readdir() is unsafe in multithread applications. readdir_r() is safe, and should be used instead. Solaris 2.4 and earlier releases provided a readdir_r() interface as specified in POSIX.1c Draft 6. The final POSIX.1c standard changed the interface as described above. SunOS 5.6 Last change: 20 Mar 1997 3 C Library Functions readdir(3C) Support for the Draft 6 interface is provided for compati- bility only and may not be supported in future releases. New applications and libraries should use the POSIX standard interface. For POSIX.1c complaint applications, the _POSIX_PTHREAD_SEMANTICS and _REENTRANT flags are automati- cally turned on by defining the _POSIX_C_SOURCE flag with a value >= 199506L. SunOS 5.6 Last change: 20 Mar 1997 4
C Library Functions readdir(3C) NAME readdir, readdir_r - read directory SYNOPSIS #include <sys/types.h> #include <dirent.h> struct dirent *readdir(DIR *_d_i_r_p); struct dirent *readdir_r(DIR *_d_i_r_p, struct dirent *_e_n_t_r_y); POSIX cc [ _f_l_a_g ... ] _f_i_l_e ... -D_POSIX_PTHREAD_SEMANTICS [ _l_i_b_r_a_r_y ... ] int *readdir_r(DIR *_d_i_r_p, struct dirent *_e_n_t_r_y, struct dirent **_r_e_s_u_l_t); DESCRIPTION The type DIR, which is defined in the header <dirent.h>, represents a _d_i_r_e_c_t_o_r_y _s_t_r_e_a_m, which is an ordered sequence of all the directory entries in a particular directory. Directory entries represent files; files may be removed from a directory or added to a directory asynchronously to the operation of readdir() and readdir_r(). readdir() The readdir() function returns a pointer to a structure representing the directory entry at the current position in the directory stream specified by the argument _d_i_r_p, and positions the directory stream at the next entry. It returns a null pointer upon reaching the end of the direc- tory stream. The structure dirent defined by the <dirent.h> header describes a directory entry. If entries for dot or dot-dot exist, one entry will be returned for dot and one entry will be returned for dot-dot; otherwise they will not be returned. The pointer returned by readdir() points to data which may be overwritten by another call to readdir() on the same directory stream. This data is not overwritten by another call to readdir() on a different directory stream. If a file is removed from or added to the directory after the most recent call to opendir(3C) or rewinddir(3C), whether a subsequent call to readdir() returns an entry for that file is unspecified. The readdir() function may buffer several directory entries per actual read operation; readdir() marks for update the _s_t__a_t_i_m_e field of the directory each time the directory is SunOS 5.6 Last change: 20 Mar 1997 1 C Library Functions readdir(3C) actually read. After a call to fork(2), either the parent or child (but not both) may continue processing the directory stream using readdir(), rewinddir() or seekdir(3C). If both the parent and child processes use these functions, the result is unde- fined. If the entry names a symbolic link, the value of the d_ino member is unspecified. readdir_r() The readdir_r() function is equivalent to readdir() except that a buffer _r_e_s_u_l_t must be supplied by the caller to store the result. The size should be sizeof(struct dirent) + {NAME_MAX} (that is, pathconf(_PC_NAME_MAX)) + 1. _PC_NAME_MAX is defined in <unistd.h>. The POSIX version (see standards(5)) of the readdir_r() function initializes the structure referenced by _e_n_t_r_y and stores a pointer to this structure in _r_e_s_u_l_t. RETURN VALUES Upon successful completion, readdir() and readdir_r() return a pointer to an object of type struct dirent. When an error is encountered, a null pointer is returned and errno is set to indicate the error. When the end of the directory is encountered, a null pointer is returned and errno is not changed. The POSIX readdir_r() returns 0 if successful or an error number to indicate failure. ERRORS The readdir() function will fail if: EOVERFLOW One of the values in the structure to be returned cannot be represented correctly. The readdir() and readdir_r() functions will fail if: EBADF The file descriptor determined by the DIR stream is no longer valid. This results if the DIR stream has been closed. ENOENT The current file pointer for the directory is not located at a valid entry. The readdir() and readdir_r() functions may fail if: EBADF The _d_i_r_p argument does not refer to an open directory stream. ENOENT The current position of the directory stream SunOS 5.6 Last change: 20 Mar 1997 2 C Library Functions readdir(3C) is invalid. USAGE The readdir() function should be used in conjunction with opendir(), closedir(), and rewinddir() to examine the con- tents of the directory. As readdir() returns a null pointer both at the end of the directory and on error, an applica- tion wishing to check for error situations should set errno to 0, then call readdir(), then check errno and if it is non-zero, assume an error has occurred. The readdir() and readdir_r() functions have explicit 64-bit equivalents. See interface64(5). EXAMPLES The following sample code will search the current directory for the entry _n_a_m_e: dirp = opendir("."); while ((dp = readdir(dirp)) != NULL) if (strcmp(dp->d_name, name) == 0) { closedir(dirp); return FOUND; } closedir(dirp); return NOT_FOUND; ATTRIBUTES See attributes(5) for descriptions of the following attri- butes: ___________________________________ | ATTRIBUTE TYPE| ATTRIBUTE VALUE | |_______________________________|______________________________________|_ | MT-Level | See NOTES below.| |________________|___________________| SEE ALSO fork(2), lstat(2), symlink(2), Intro(3), closedir(3C), opendir(3C), rewinddir(3C), seekdir(3C), attributes(5), interface64(5), standards(5) NOTES When compiling multithread programs, see Intro(3), _N_o_t_e_s _O_n _M_u_l_t_i_t_h_r_e_a_d _A_p_p_l_i_c_a_t_i_o_n_s. readdir() is unsafe in multithread applications. readdir_r() is safe, and should be used instead. Solaris 2.4 and earlier releases provided a readdir_r() interface as specified in POSIX.1c Draft 6. The final POSIX.1c standard changed the interface as described above. SunOS 5.6 Last change: 20 Mar 1997 3 C Library Functions readdir(3C) Support for the Draft 6 interface is provided for compati- bility only and may not be supported in future releases. New applications and libraries should use the POSIX standard interface. For POSIX.1c complaint applications, the _POSIX_PTHREAD_SEMANTICS and _REENTRANT flags are automati- cally turned on by defining the _POSIX_C_SOURCE flag with a value >= 199506L. SunOS 5.6 Last change: 20 Mar 1997 4