blob: 1264c38b1cc3f78f30844e61d3c69754fb7fff1b [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*
2 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
3 *
4 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
5 */
6
7#include <_lfs_64.h>
8
9#include <errno.h>
10#include <stdlib.h>
11#include <string.h>
12#include <unistd.h>
13#include <dirent.h>
14#include "dirstream.h"
15
16struct dirent64 *readdir64(DIR * dir)
17{
18 ssize_t bytes;
19 struct dirent64 *de;
20
21 if (!dir) {
22 __set_errno(EBADF);
23 return NULL;
24 }
25
26 __UCLIBC_MUTEX_LOCK(dir->dd_lock);
27
28 do {
29 if (dir->dd_size <= dir->dd_nextloc) {
30 /* read dir->dd_max bytes of directory entries. */
31 bytes = __getdents64(dir->dd_fd, dir->dd_buf, dir->dd_max);
32 if (bytes <= 0) {
33 de = NULL;
34 goto all_done;
35 }
36 dir->dd_size = bytes;
37 dir->dd_nextloc = 0;
38 }
39
40 de = (struct dirent64 *) (((char *) dir->dd_buf) + dir->dd_nextloc);
41
42 /* Am I right? H.J. */
43 dir->dd_nextloc += de->d_reclen;
44
45 /* We have to save the next offset here. */
46 dir->dd_nextoff = de->d_off;
47
48 /* Skip deleted files. */
49 } while (de->d_ino == 0);
50
51all_done:
52 __UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
53
54 return de;
55}
56libc_hidden_def(readdir64)