• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <dirent.h>
2 #include <fcntl.h>
3 #include <sys/stat.h>
4 #include <errno.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include "__dirent.h"
8 
9 extern uint64_t __get_dir_tag(DIR* dir);
10 
fdopendir(int fd)11 DIR *fdopendir(int fd)
12 {
13 	DIR *dir;
14 	struct stat st;
15 
16 	if (fstat(fd, &st) < 0) {
17 		return 0;
18 	}
19 	if (fcntl(fd, F_GETFL) & O_PATH) {
20 		errno = EBADF;
21 		return 0;
22 	}
23 	if (!S_ISDIR(st.st_mode)) {
24 		errno = ENOTDIR;
25 		return 0;
26 	}
27 	if (!(dir = calloc(1, sizeof *dir))) {
28 		return 0;
29 	}
30 
31 	fcntl(fd, F_SETFD, FD_CLOEXEC);
32 	dir->fd = fd;
33 #ifndef __LITEOS__
34 	fdsan_exchange_owner_tag(fd, 0, __get_dir_tag(dir));
35 #endif
36 	return dir;
37 }
38