Annotation of researchv10no/cmd/asd/readdir.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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