Annotation of researchv9/cmd/sh/readdir.c, revision 1.1

1.1     ! root        1: /* Copyright (c) 1982 Regents of the University of California */
        !             2: 
        !             3: static char sccsid[] = "@(#)readdir.c 4.2 3/12/82";
        !             4: 
        !             5: #include <sys/types.h>
        !             6: #include <ndir.h>
        !             7: 
        !             8: /*
        !             9:  * read an old stlye directory entry and present it as a new one
        !            10:  */
        !            11: #define        ODIRSIZ 14
        !            12: 
        !            13: struct olddirect {
        !            14:        ino_t   d_ino;
        !            15:        char    d_name[ODIRSIZ];
        !            16: #ifdef CRAY
        !            17:        char    d_pad[10];
        !            18: #endif
        !            19: };
        !            20: 
        !            21: /*
        !            22:  * get next entry in a directory.
        !            23:  */
        !            24: struct direct *
        !            25: readdir(dirp)
        !            26:        register DIR *dirp;
        !            27: {
        !            28:        register struct olddirect *dp;
        !            29:        static struct direct dir;
        !            30: 
        !            31:        for (;;) {
        !            32:                if (dirp->dd_loc == 0) {
        !            33:                        dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, 
        !            34:                            DIRBLKSIZ);
        !            35:                        if (dirp->dd_size <= 0)
        !            36:                                return NULL;
        !            37:                }
        !            38:                if (dirp->dd_loc >= dirp->dd_size) {
        !            39:                        dirp->dd_loc = 0;
        !            40:                        continue;
        !            41:                }
        !            42:                dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc);
        !            43:                dirp->dd_loc += sizeof(struct olddirect);
        !            44:                if (dp->d_ino == 0)
        !            45:                        continue;
        !            46:                dir.d_ino = dp->d_ino;
        !            47:                strncpy(dir.d_name, dp->d_name, ODIRSIZ);
        !            48:                dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
        !            49:                dir.d_namlen = strlen(dir.d_name);
        !            50:                dir.d_reclen = DIRSIZ(&dir);
        !            51:                return (&dir);
        !            52:        }
        !            53: }

unix.superglobalmegacorp.com

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