summaryrefslogtreecommitdiff
path: root/userland/libc/dirent/readdir.c
blob: 3e1460c312a21c5d6e6ed08ad50b7db02edc0045 (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
#include <dirent.h>
#include <stdio.h>
#include <unistd.h>

int readdir_multi(DIR *dir, struct dirent *entries, int num_entries) {
  int rc;
  if (-1 ==
      (rc = read(dir->fd, entries, num_entries * sizeof(struct dirent)))) {
    return -1;
  }

  int num_read_entries = rc / sizeof(struct dirent);
  return num_read_entries;
}

struct dirent *readdir(DIR *dir) {
  int rc;
  if (-1 ==
      (rc = read(dir->fd, &dir->internal_direntry, sizeof(struct dirent)))) {
    return NULL;
  }
  if (rc < (int)sizeof(struct dirent)) {
    return NULL;
  }

  return &(dir->internal_direntry);
}