Annotation of researchv9/libc/gen/readdir.c, revision 1.1.1.1

1.1       root        1: /* Copyright (c) 1982 Regents of the University of California */
                      2: /* and modified by pjw in 1986 */
                      3: #include <sys/types.h>
                      4: #include "ndir.h"
                      5: 
                      6: /*
                      7:  * read any style directory entry and present it as a bsd one
                      8:  */
                      9: /* classical unix */
                     10: #define        ODIRSIZ 14
                     11: struct olddirect {
                     12:        ino_t   d_ino;
                     13:        char    d_name[ODIRSIZ];
                     14: };
                     15: /* current cray */
                     16: #define CDIRSIZ 24
                     17: struct craydirect {
                     18:        long x;
                     19:        long d_ino;
                     20:        char d_name[CDIRSIZ];
                     21: };
                     22: 
                     23: /*
                     24:  * get next entry in a directory.
                     25:  */
                     26: struct direct *
                     27: readdir(dirp)
                     28:        register DIR *dirp;
                     29: {
                     30:        register struct olddirect *dp;
                     31:        register struct craydirect *cp;
                     32:        register struct direct *np;
                     33:        static struct direct dir;
                     34: 
                     35: loop:
                     36:        if (dirp->dd_loc == 0) {
                     37:                dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, 
                     38:                    DIRBLKSIZ);
                     39:                if (dirp->dd_size <= 0)
                     40:                        return NULL;
                     41:        }
                     42:        if (dirp->dd_loc >= dirp->dd_size) {
                     43:                dirp->dd_loc = 0;
                     44:                goto loop;
                     45:        }
                     46:        switch(dirp->dd_type) {
                     47:        case TCRAY:
                     48:                cp = (struct craydirect *) (dirp->dd_buf + dirp->dd_loc);
                     49:                dirp->dd_loc += sizeof(struct craydirect);
                     50:                if(cp->d_ino == 0)
                     51:                        goto loop;
                     52:                strncpy(dir.d_name, cp->d_name, CDIRSIZ);
                     53:                dir.d_name[CDIRSIZ] = 0;
                     54:                dir.d_ino = (ino_t) dir_rev4(cp->d_ino);
                     55:                break;
                     56:        default:
                     57:        case TUNK:
                     58:                return(0);
                     59:        case TOLD:
                     60:                dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc);
                     61:                dirp->dd_loc += sizeof(struct olddirect);
                     62:                if (dp->d_ino == 0)
                     63:                        goto loop;
                     64:                dir.d_ino = (ino_t) dp->d_ino;
                     65:                strncpy(dir.d_name, dp->d_name, ODIRSIZ);
                     66:                dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
                     67:                break;
                     68:        case TSUN:
                     69:                np = (struct direct *)(dirp->dd_buf + dirp->dd_loc);
                     70:                dirp->dd_loc += dir_rev2(np->d_reclen);
                     71:                if(np->d_ino == 0)
                     72:                        goto loop;
                     73:                dir.d_ino = (ino_t) dir_rev4(np->d_ino);
                     74:                strcpy(dir.d_name, np->d_name);
                     75:                break;
                     76:        case TBSD:
                     77:                np = (struct direct *)(dirp->dd_buf + dirp->dd_loc);
                     78:                dirp->dd_loc += np->d_reclen;
                     79:                if(np->d_ino == 0)
                     80:                        goto loop;
                     81:                dir.d_ino = (ino_t) np->d_ino;
                     82:                strcpy(dir.d_name, np->d_name);
                     83:                break;
                     84:        }
                     85:        dir.d_namlen = strlen(dir.d_name);
                     86:        dir.d_reclen = DIRSIZ(&dir);
                     87:        return (&dir);
                     88: }
                     89: 
                     90: dir_rev2(n)
                     91: {      union {
                     92:                short x;
                     93:                unsigned char b[2];
                     94:        } u;
                     95:        u.b[1] = n & 0xff;
                     96:        u.b[0] = (n >> 8) & 0xff;
                     97:        return(u.x);
                     98: }
                     99: 
                    100: dir_rev4(n)
                    101: {      union {
                    102:                long x;
                    103:                unsigned char b[4];
                    104:        } u;
                    105:        u.b[3] = n & 0xff;
                    106:        u.b[2] = (n >> 8) & 0xff;
                    107:        u.b[1] = (n >> 16) & 0xff;
                    108:        u.b[0] = (n >> 24) & 0xff;
                    109:        return(u.x);
                    110: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.