Line | |
---|
1 | /* readdir() Author: Kees J. Bot
|
---|
2 | * 24 Apr 1989
|
---|
3 | */
|
---|
4 | #define nil 0
|
---|
5 | #include <lib.h>
|
---|
6 | #define read _read
|
---|
7 | #define readdir _readdir
|
---|
8 | #include <sys/types.h>
|
---|
9 | #include <sys/stat.h>
|
---|
10 | #include <dirent.h>
|
---|
11 | #include <unistd.h>
|
---|
12 | #include <stdlib.h>
|
---|
13 | #include <fcntl.h>
|
---|
14 | #include <limits.h>
|
---|
15 | #include <errno.h>
|
---|
16 | #include <string.h>
|
---|
17 |
|
---|
18 | #define v7ent(p) ((struct _v7_direct *) (p))
|
---|
19 | #define V7_EXTENT (sizeof(struct _v7_direct) / sizeof(struct _fl_direct) - 1)
|
---|
20 |
|
---|
21 | struct dirent *readdir(DIR *dp)
|
---|
22 | /* Return the next entry in a directory. Handle V7 and FLEX format dirs. */
|
---|
23 | {
|
---|
24 | struct dirent *e;
|
---|
25 |
|
---|
26 | if (dp == nil) { errno= EBADF; return nil; }
|
---|
27 |
|
---|
28 | do {
|
---|
29 | if (dp->_count <= 0) {
|
---|
30 | /* Read the next directory block. */
|
---|
31 | dp->_count= read(dp->_fd, dp->_buf, sizeof(dp->_buf));
|
---|
32 | if (dp->_count <= 0) return nil;
|
---|
33 |
|
---|
34 | dp->_count/= sizeof(dp->_buf[0]);
|
---|
35 | dp->_ptr= dp->_buf;
|
---|
36 |
|
---|
37 | /* Extent is zero of the first flex entry. */
|
---|
38 | if (dp->_v7 == (char)-1) dp->_v7= dp->_buf[0].d_extent;
|
---|
39 | }
|
---|
40 |
|
---|
41 | if (!dp->_v7) {
|
---|
42 | /* FLEX. */
|
---|
43 | e= (struct dirent *) dp->_ptr;
|
---|
44 | } else {
|
---|
45 | /* V7: transform to FLEX. */
|
---|
46 | e= (struct dirent *) dp->_v7f;
|
---|
47 | e->d_ino= v7ent(dp->_ptr)->d_ino;
|
---|
48 | e->d_extent= V7_EXTENT;
|
---|
49 | memcpy(e->d_name, v7ent(dp->_ptr)->d_name, DIRSIZ);
|
---|
50 | e->d_name[DIRSIZ]= 0;
|
---|
51 | }
|
---|
52 |
|
---|
53 | dp->_ptr+= 1 + e->d_extent;
|
---|
54 | dp->_count-= 1 + e->d_extent;
|
---|
55 | dp->_pos+= (1 + e->d_extent) * sizeof(*dp->_ptr);
|
---|
56 |
|
---|
57 | } while (e->d_ino == 0);
|
---|
58 | return e;
|
---|
59 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.