this further reduces the number of source files which need to include libc.h and thereby be potentially exposed to libc global state and internals. this will also facilitate further improvements like adding an inline fast-path, if we want to do so later.
30 lines
530 B
C
30 lines
530 B
C
#include <dirent.h>
|
|
#include <errno.h>
|
|
#include <string.h>
|
|
#include "__dirent.h"
|
|
#include "lock.h"
|
|
|
|
int readdir_r(DIR *restrict dir, struct dirent *restrict buf, struct dirent **restrict result)
|
|
{
|
|
struct dirent *de;
|
|
int errno_save = errno;
|
|
int ret;
|
|
|
|
LOCK(dir->lock);
|
|
errno = 0;
|
|
de = readdir(dir);
|
|
if ((ret = errno)) {
|
|
UNLOCK(dir->lock);
|
|
return ret;
|
|
}
|
|
errno = errno_save;
|
|
if (de) memcpy(buf, de, de->d_reclen);
|
|
else buf = NULL;
|
|
|
|
UNLOCK(dir->lock);
|
|
*result = buf;
|
|
return 0;
|
|
}
|
|
|
|
weak_alias(readdir_r, readdir64_r);
|