|
|
1.1 root 1:
2: /*
3: * Copyright (c) 1982 Regents of the University of California
4: */
5:
6: static char sccsid[] = "@(#)readdir.c 4.2 3/12/82";
7:
8: #include <sys/types.h>
9: #include "ndir.h"
10:
11: /*
12: * read an old stlye directory entry and present it as a new one
13: */
14: #define ODIRSIZ 14
15:
16: struct olddirect {
17: ino_t od_ino;
18: char od_name[ODIRSIZ];
19: };
20:
21: /*
22: * get next entry in a directory.
23: */
24: struct direct *
25: readdir(dirp)
26: register DIR *dirp;
27: {
28: register struct olddirect *dp;
29: static struct direct dir;
30:
31: for (;;) {
32: if (dirp->dd_loc == 0) {
33: dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
34: DIRBLKSIZ);
35: if (dirp->dd_size <= 0)
36: return NULL;
37: }
38: if (dirp->dd_loc >= dirp->dd_size) {
39: dirp->dd_loc = 0;
40: continue;
41: }
42: dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc);
43: dirp->dd_loc += sizeof(struct olddirect);
44: if (dp->od_ino == 0)
45: continue;
46: dir.d_ino = dp->od_ino;
47: strncpy(dir.d_name, dp->od_name, ODIRSIZ);
48: dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
49: dir.d_namlen = strlen(dir.d_name);
50: dir.d_reclen = DIRSIZ(&dir);
51: return (&dir);
52: }
53: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.