projects
/
oweals
/
musl.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
fix uninitialized waiters field in semaphores
[oweals/musl.git]
/
src
/
dirent
/
fdopendir.c
1
#include <dirent.h>
2
#include <fcntl.h>
3
#include <sys/stat.h>
4
#include <errno.h>
5
#include <stdlib.h>
6
#include <unistd.h>
7
#include <limits.h>
8
#include "__dirent.h"
9
10
DIR *fdopendir(int fd)
11
{
12
DIR *dir;
13
struct stat st;
14
15
if (fstat(fd, &st) < 0 || !S_ISDIR(st.st_mode)) {
16
errno = ENOTDIR;
17
return 0;
18
}
19
if (!(dir = calloc(1, sizeof *dir))) {
20
return 0;
21
}
22
23
fcntl(fd, F_SETFD, FD_CLOEXEC);
24
dir->fd = fd;
25
return dir;
26
}