1 #include <dirent.h> 2 #include <errno.h> 3 #include <string.h> 4 #include "__dirent.h" 5 #include "lock.h" 6 readdir_r(DIR * restrict dir,struct dirent * restrict buf,struct dirent ** restrict result)7int readdir_r(DIR *restrict dir, struct dirent *restrict buf, struct dirent **restrict result) 8 { 9 struct dirent *de; 10 int errno_save = errno; 11 int ret; 12 13 LOCK(dir->lock); 14 errno = 0; 15 de = readdir(dir); 16 if ((ret = errno)) { 17 UNLOCK(dir->lock); 18 return ret; 19 } 20 errno = errno_save; 21 if (de) memcpy(buf, de, de->d_reclen); 22 else buf = NULL; 23 24 UNLOCK(dir->lock); 25 *result = buf; 26 return 0; 27 } 28 29 weak_alias(readdir_r, readdir64_r); 30