OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [misc/] [dirent/] [readdir64.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
#include <features.h>
2
#ifdef __UCLIBC_HAS_LFS__
3
#if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS != 64 
4
#undef _FILE_OFFSET_BITS
5
#define _FILE_OFFSET_BITS   64
6
#endif
7
#ifndef __USE_LARGEFILE64
8
# define __USE_LARGEFILE64      1
9
#endif
10
/* We absolutely do _NOT_ want interfaces silently
11
 * renamed under us or very bad things will happen... */
12
#ifdef __USE_FILE_OFFSET64
13
# undef __USE_FILE_OFFSET64
14
#endif
15
#include <dirent.h>
16
#include <errno.h>
17
#include <stdlib.h>
18
#include <string.h>
19
#include <unistd.h>
20
#include <dirent.h>
21
#include "dirstream.h"
22
 
23
 
24
struct dirent64 *readdir64(DIR * dir)
25
{
26
        ssize_t bytes;
27
        struct dirent64 *de;
28
 
29
        if (!dir) {
30
                __set_errno(EBADF);
31
                return NULL;
32
        }
33
 
34
#ifdef __UCLIBC_HAS_THREADS__
35
        __pthread_mutex_lock(&(dir->dd_lock));
36
#endif
37
 
38
        do {
39
            if (dir->dd_size <= dir->dd_nextloc) {
40
                /* read dir->dd_max bytes of directory entries. */
41
                bytes = __getdents64(dir->dd_fd, dir->dd_buf, dir->dd_max);
42
                if (bytes <= 0) {
43
                    de = NULL;
44
                    goto all_done;
45
                }
46
                dir->dd_size = bytes;
47
                dir->dd_nextloc = 0;
48
            }
49
 
50
            de = (struct dirent64 *) (((char *) dir->dd_buf) + dir->dd_nextloc);
51
 
52
            /* Am I right? H.J. */
53
            dir->dd_nextloc += de->d_reclen;
54
 
55
            /* We have to save the next offset here. */
56
            dir->dd_nextoff = de->d_off;
57
 
58
            /* Skip deleted files.  */
59
        } while (de->d_ino == 0);
60
 
61
all_done:
62
#ifdef __UCLIBC_HAS_THREADS__
63
        __pthread_mutex_unlock(&(dir->dd_lock));
64
#endif
65
 
66
        return de;
67
}
68
 
69
#endif /* __UCLIBC_HAS_LFS__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.