|
|
1.1 root 1: #ifndef BSD4_2
2:
3: #include <sys/types.h>
4: #include <ndir.h>
5:
6: /*
7: * read an old stlye directory entry and present it as a new one
8: */
9: #define ODIRSIZ 14
10:
11: struct olddirect {
12: ino_t d_ino;
13: char d_name[ODIRSIZ];
14: char d_pad[10];
15: };
16:
17: /*
18: * get next entry in a directory.
19: */
20: struct direct *
21: readdir(dirp)
22: register DIR *dirp;
23: {
24: register struct olddirect *dp;
25: static struct direct dir;
26:
27: for (;;) {
28: if (dirp->dd_loc == 0) {
29: dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
30: DIRBLKSIZ);
31: if (dirp->dd_size <= 0)
32: return NULL;
33: }
34: if (dirp->dd_loc >= dirp->dd_size) {
35: dirp->dd_loc = 0;
36: continue;
37: }
38: dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc);
39: dirp->dd_loc += sizeof(struct olddirect);
40: if (dp->d_ino == 0)
41: continue;
42: dir.d_ino = dp->d_ino;
43: strncpy(dir.d_name, dp->d_name, ODIRSIZ);
44: dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
45: dir.d_namlen = strlen(dir.d_name);
46: dir.d_reclen = DIRSIZ(&dir);
47: return (&dir);
48: }
49: }
50: #endif
51:
52: #ifndef BSD4_2
53:
54: DIR *
55: opendir(name)
56: register char *name;
57: {
58: DIR dirbuf, *dirp;
59: struct stat statb;
60: char buf[MAXNAMELEN+1];
61: register char *s;
62:
63: *(movstrn(name, buf, MAXNAMELEN)) = 0;
64: for (s=buf; *s; s++)
65: *s &= STRIP;
66: if ((dirbuf.dd_fd = open(buf, 0)) < 0)
67: return(NULL);
68: if (fstat(dirbuf.dd_fd, &statb)!=0 || (statb.st_mode & S_IFMT)!=S_IFDIR){
69: close(dirbuf.dd_fd);
70: return(NULL);
71: }
72: dirbuf.dd_loc = 0;
73: dirp = (DIR *)shalloc(sizeof(DIR));
74: *dirp = dirbuf;
75: return(dirp);
76: }
77:
78: void
79: closedir(dirp)
80: DIR *dirp;
81: {
82: close(dirp->dd_fd);
83: shfree((char *)dirp);
84: }
85:
86: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.