summaryrefslogtreecommitdiff
path: root/src/dirent/readdir_r.c
blob: 58f603257a3600cd4eddd96b7dd1988c240299c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <dirent.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "__dirent.h"
#include "libc.h"

int readdir_r(DIR *dir, struct dirent *buf, struct dirent **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;
}

LFS64_2(readdir_r, readdir64_r);