summaryrefslogtreecommitdiff
path: root/userland/libc/dirent/opendir.c
blob: efe8b6de55771410c1a13784e8e5e203b7aff89d (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
#include <dirent.h>

DIR *fdopendir(int fd) {
  DIR *rc = malloc(sizeof(DIR));
  if (!rc) {
    return NULL;
  }
  rc->fd = fd;
  rc->dir_num = 0;
  return rc;
}

DIR *opendir(const char *dirname) {
  int fd = open(dirname, O_RDONLY, 0);
  if (-1 == fd) {
    return NULL;
  }
  DIR *rc = malloc(sizeof(DIR));
  if (!rc) {
    return NULL;
  }
  rc->fd = fd;
  rc->dir_num = 0;
  return rc;
}