X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/e3cf15b684ccf1496b6a682c8d46192674711eb2..9385eb3d10ebe5eb398c52040ec3dbfba9b0cdcf:/gen/readdir_r.c?ds=inline diff --git a/gen/readdir_r.c b/gen/readdir_r.c deleted file mode 100644 index 8e19ccc..0000000 --- a/gen/readdir_r.c +++ /dev/null @@ -1,51 +0,0 @@ -#include -#include -#include - -/* - * Synopsis: - * dir_table is a global static array of pthread mutexes. The array is NMUTEXES - * in length (NMUTEXES * sizeof(pthread_mutex_t)). - * - * Whenever a call to readdir_r is made, the element in the array indexed by the - * modulus of the file descriptor associated with dirp is locked, and readdir is - * called on dirp. The result is returned in readdir_r semantics and the - * element in dir_table is unlocked. - */ - -static pthread_mutex_t dir_table[] = { - PTHREAD_MUTEX_INITIALIZER, - PTHREAD_MUTEX_INITIALIZER, - PTHREAD_MUTEX_INITIALIZER, - PTHREAD_MUTEX_INITIALIZER, - PTHREAD_MUTEX_INITIALIZER, - PTHREAD_MUTEX_INITIALIZER, - PTHREAD_MUTEX_INITIALIZER, - PTHREAD_MUTEX_INITIALIZER -#define NMUTEXES 8 -}; - -int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) -{ - int ret; - int mindex = dirp->dd_fd % NMUTEXES; - struct dirent *tmpdp; - - pthread_mutex_lock(&dir_table[mindex]); - - tmpdp = readdir(dirp); - if( tmpdp == NULL ) { - *result = NULL; - ret = errno; - pthread_mutex_unlock(&dir_table[mindex]); - return ret; - } - - memcpy(entry, tmpdp, sizeof(struct dirent)); - *result = entry; - - pthread_mutex_unlock(&dir_table[mindex]); - return 0; -} - -