OSDN Git Service

Last portion of libc_hidden_proto removal.
[uclinux-h8/uClibc.git] / libc / misc / dirent / readdir64.c
1 /*
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
16 /* libc_hidden_proto(readdir64) */
17 struct dirent64 *readdir64(DIR * dir)
18 {
19         ssize_t bytes;
20         struct dirent64 *de;
21
22         if (!dir) {
23                 __set_errno(EBADF);
24                 return NULL;
25         }
26
27         __UCLIBC_MUTEX_LOCK(dir->dd_lock);
28
29         do {
30             if (dir->dd_size <= dir->dd_nextloc) {
31                 /* read dir->dd_max bytes of directory entries. */
32                 bytes = __getdents64(dir->dd_fd, dir->dd_buf, dir->dd_max);
33                 if (bytes <= 0) {
34                     de = NULL;
35                     goto all_done;
36                 }
37                 dir->dd_size = bytes;
38                 dir->dd_nextloc = 0;
39             }
40
41             de = (struct dirent64 *) (((char *) dir->dd_buf) + dir->dd_nextloc);
42
43             /* Am I right? H.J. */
44             dir->dd_nextloc += de->d_reclen;
45
46             /* We have to save the next offset here. */
47             dir->dd_nextoff = de->d_off;
48
49             /* Skip deleted files.  */
50         } while (de->d_ino == 0);
51
52 all_done:
53         __UCLIBC_MUTEX_UNLOCK(dir->dd_lock);
54
55         return de;
56 }
57 libc_hidden_def(readdir64)