Annotation of 42BSD/usr.lib/sendmail/lib/libndir/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.3 8/8/82";
        !             4: 
        !             5: #include <sys/types.h>
        !             6: #include <dir.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   od_ino;
        !            15:        char    od_name[ODIRSIZ];
        !            16: };
        !            17: 
        !            18: /*
        !            19:  * get next entry in a directory.
        !            20:  */
        !            21: struct direct *
        !            22: readdir(dirp)
        !            23:        register DIR *dirp;
        !            24: {
        !            25:        register struct olddirect *dp;
        !            26:        static struct direct dir;
        !            27: 
        !            28:        for (;;) {
        !            29:                if (dirp->dd_loc == 0) {
        !            30:                        dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, 
        !            31:                            DIRBLKSIZ);
        !            32:                        if (dirp->dd_size <= 0)
        !            33:                                return NULL;
        !            34:                }
        !            35:                if (dirp->dd_loc >= dirp->dd_size) {
        !            36:                        dirp->dd_loc = 0;
        !            37:                        continue;
        !            38:                }
        !            39:                dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc);
        !            40:                dirp->dd_loc += sizeof(struct olddirect);
        !            41:                if (dp->od_ino == 0)
        !            42:                        continue;
        !            43:                dir.d_ino = dp->od_ino;
        !            44:                strncpy(dir.d_name, dp->od_name, ODIRSIZ);
        !            45:                dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
        !            46:                dir.d_namlen = strlen(dir.d_name);
        !            47:                dir.d_reclen = DIRBLKSIZ;
        !            48:                return (&dir);
        !            49:        }
        !            50: }

unix.superglobalmegacorp.com

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