|
|
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;
1.1.1.2 ! root 18: struct stat st;
1.1 root 19:
20: dirp = (DIR *)malloc(sizeof(DIR));
21: if(!dirp)
22: return(0);
23: dirp->dd_fd = open(name, 0);
24: if (dirp->dd_fd == -1) {
25: free(dirp);
26: return(0);
27: }
28: dirp->dd_loc = 0;
29: i = read(dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ);
30: if(i <= 0) {
31: close(dirp->dd_fd);
32: free(dirp);
33: return(0);
34: }
35: lseek(dirp->dd_fd, 0L, 0);
36: /* the cray and the 68000 are big-endians, vax is not
37: v9: ??.0000000000000??..000000000000|||||||||
38: cray: ????????.00000000000000000000000????????..0000000000000000000000|||||||
39: 68k: ????0X01.000????0X02..00|||||||| X=12
40: vaxn: ????X010.000????X020..00|||||||
41: /* shortest cray sys v dir is 64 bytes, shortest v8 is 32, and shortest
42: * sun 4.2(68k) is 24 (except it's supposed to be a whole block long)
43: */
44: if(i < 24) /* mysteriously short directory */
45: goto old;
46: p = dirp->dd_buf;
47: if(p[8] != '.') {
48: old:
1.1.1.2 ! root 49: if (fstat(dirp->dd_fd, &st) < 0) {
! 50: close(dirp->dd_fd);
! 51: free(dirp);
! 52: return(0);
! 53: }
! 54: if (st.st_ino == *(ino_t *)dirp->dd_buf)
! 55: dirp->dd_type = TOLD;
! 56: else
! 57: dirp->dd_type = TOLDSWAP;
1.1 root 58: return(dirp);
59: }
60: if(p[20] == '.' && p[21] == '.') { /* bsd-like or bogus */
1.1.1.2 ! root 61: if(*(short *)&p[4] == 0x000c) {
! 62: dirp->dd_type = TBSD;
1.1 root 63: return(dirp);
64: }
1.1.1.2 ! root 65: if(*(short *)&p[4] == 0x0c00) {
! 66: dirp->dd_type = TBSDSWAP;
1.1 root 67: return(dirp);
68: }
69: dirp->dd_type = TUNK;
70: return(dirp);
71: }
72: if(i >= 32 && p[9] == 0 && p[40] == '.' && p[41] == '.' && p[42] == 0) {
73: dirp->dd_type = TCRAY;
74: return(dirp);
75: }
76: dirp->dd_type = TUNK;
77: return(dirp);
78: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.