1: #include "defs.h"
2: #if !defined(BSD4_2) && !defined(BSD4_1C)
3: #include <sys/param.h>
4: #include "ndir.h"
5:
6: #ifdef SCCSID
7: static char *SccsId = "@(#)ndir.c 1.8 4/26/85";
8: #endif /* SCCSID */
9:
10: /*
11: * support for Berkeley directory reading routine on a V7 file system
12: */
13:
14: extern char *malloc();
15:
16: /*
17: * open a directory.
18: */
19: DIR *
20: opendir(name)
21: char *name;
22: {
23: register DIR *dirp;
24: register int fd;
25:
26: if ((fd = open(name, 0)) == -1)
27: return NULL;
28: if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
29: close (fd);
30: return NULL;
31: }
32: dirp->dd_fd = fd;
33: dirp->dd_loc = 0;
34: return dirp;
35: }
36:
37: /*
38: * read an old style directory entry and present it as a new one
39: */
40: #ifdef pyr
41: /* Pyramid in the AT&T universe */
42: #define ODIRSIZ 248
43: struct olddirect {
44: long od_ino;
45: short od_fill1, od_fill2;
46: char od_name[ODIRSIZ];
47: };
48: #else /* V7 file system */
49: #define ODIRSIZ 14
50:
51: struct olddirect {
52: short od_ino;
53: char od_name[ODIRSIZ];
54: };
55: #endif /* V7 */
56:
57: /*
58: * get next entry in a directory.
59: */
60: struct direct *
61: readdir(dirp)
62: register DIR *dirp;
63: {
64: register struct olddirect *dp;
65: static struct direct dir;
66:
67: for (;;) {
68: if (dirp->dd_loc == 0) {
69: dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
70: DIRBLKSIZ);
71: if (dirp->dd_size <= 0)
72: return NULL;
73: }
74: if (dirp->dd_loc >= dirp->dd_size) {
75: dirp->dd_loc = 0;
76: continue;
77: }
78: dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc);
79: dirp->dd_loc += sizeof(struct olddirect);
80: if (dp->od_ino == 0)
81: continue;
82: dir.d_ino = dp->od_ino;
83: strncpy(dir.d_name, dp->od_name, ODIRSIZ);
84: dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
85: dir.d_namlen = strlen(dir.d_name);
86: dir.d_reclen = DIRSIZ(&dir);
87: return (&dir);
88: }
89: }
90:
91: /*
92: * close a directory.
93: */
94: void
95: closedir(dirp)
96: register DIR *dirp;
97: {
98: close(dirp->dd_fd);
99: dirp->dd_fd = -1;
100: dirp->dd_loc = 0;
101: free((char *)dirp);
102: }
103: #endif /* !BSD4_2 && !BSD4_1C */
Defined functions
Defined variables
SccsId
defined in line
7;
never used
Defined struct's
Defined macros