|
|
1.1 root 1: /* Copyright (c) 1982 Regents of the University of California, who write
2: lousy code */
3: /* and modified by pjw in 1986 */
4:
5: #include <sys/types.h>
6: #include <sys/stat.h>
7: #include "ndir.h"
8:
9: /*
10: * open a directory.
11: */
12: DIR *
13: opendir(name)
14: char *name;
15: { int i;
16: register DIR *dirp;
17: register char *p;
18:
19: dirp = (DIR *)malloc(sizeof(DIR));
20: if(!dirp)
21: return(0);
22: dirp->dd_fd = open(name, 0);
23: if (dirp->dd_fd == -1) {
24: free(dirp);
25: return(0);
26: }
27: dirp->dd_loc = 0;
28: i = read(dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ);
29: if(i <= 0) {
30: close(dirp->dd_fd);
31: free(dirp);
32: return(0);
33: }
34: lseek(dirp->dd_fd, 0L, 0);
35: /* the cray and the 68000 are big-endians, vax is not
36: v9: ??.0000000000000??..000000000000|||||||||
37: cray: ????????.00000000000000000000000????????..0000000000000000000000|||||||
38: 68k: ????0X01.000????0X02..00|||||||| X=12
39: vaxn: ????X010.000????X020..00|||||||
40: /* shortest cray sys v dir is 64 bytes, shortest v8 is 32, and shortest
41: * sun 4.2(68k) is 24 (except it's supposed to be a whole block long)
42: */
43: if(i < 24) /* mysteriously short directory */
44: goto old;
45: p = dirp->dd_buf;
46: if(p[8] != '.') {
47: old:
48: dirp->dd_type = TOLD;
49: return(dirp);
50: }
51: if(p[20] == '.' && p[21] == '.') { /* bsd-like or bogus */
52: if(p[4] == 0 && p[5] == 12) {
53: dirp->dd_type = TSUN;
54: return(dirp);
55: }
56: if(p[4] == 12 && p[5] == 0) {
57: dirp->dd_type = TBSD;
58: return(dirp);
59: }
60: dirp->dd_type = TUNK;
61: return(dirp);
62: }
63: if(i >= 32 && p[9] == 0 && p[40] == '.' && p[41] == '.' && p[42] == 0) {
64: dirp->dd_type = TCRAY;
65: return(dirp);
66: }
67: dirp->dd_type = TUNK;
68: return(dirp);
69: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.