Annotation of 43BSD/contrib/rn/ndir.c, revision 1.1.1.1

1.1       root        1: /* $Header: ndir.c,v 4.3.1.3 85/05/23 11:19:24 lwall Exp $
                      2:  *
                      3:  * $Log:       ndir.c,v $
                      4:  * Revision 4.3.1.3  85/05/23  11:19:24  lwall
                      5:  * Oops, shouldn't have included sys/types.h again.
                      6:  * 
                      7:  * Revision 4.3.1.2  85/05/15  14:46:00  lwall
                      8:  * Changed short to ino_t, which may be ushort on some systems.
                      9:  * 
                     10:  * Revision 4.3.1.1  85/05/10  11:35:34  lwall
                     11:  * Branch for patches.
                     12:  * 
                     13:  * Revision 4.3  85/05/01  11:42:55  lwall
                     14:  * Baseline for release with 4.3bsd.
                     15:  * 
                     16:  */
                     17: 
                     18: #include "EXTERN.h"
                     19: #include "common.h"
                     20: #include "INTERN.h"
                     21: #include "ndir.h"
                     22: 
                     23: #ifdef USENDIR
                     24: /*
                     25:  * support for Berkeley directory reading routine on a V7 file system
                     26:  */
                     27: 
                     28: /*
                     29:  * open a directory.
                     30:  */
                     31: DIR *
                     32: opendir(name)
                     33: char *name;
                     34: {
                     35:        register DIR *dirp;
                     36:        register int fd;
                     37: 
                     38:        if ((fd = open(name, 0)) == -1)
                     39:                return NULL;
                     40:        if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
                     41:                close (fd);
                     42:                return NULL;
                     43:        }
                     44:        dirp->dd_fd = fd;
                     45:        dirp->dd_loc = 0;
                     46:        return dirp;
                     47: }
                     48: 
                     49: /*
                     50:  * read an old style directory entry and present it as a new one
                     51:  */
                     52: #ifndef pyr
                     53: #define        ODIRSIZ 14
                     54: 
                     55: struct olddirect {
                     56:        ino_t   od_ino;
                     57:        char    od_name[ODIRSIZ];
                     58: };
                     59: #else  an Pyramid in the ATT universe
                     60: #define        ODIRSIZ 248
                     61: 
                     62: struct olddirect {
                     63:        long    od_ino;
                     64:        short   od_fill1, od_fill2;
                     65:        char    od_name[ODIRSIZ];
                     66: };
                     67: #endif
                     68: 
                     69: /*
                     70:  * get next entry in a directory.
                     71:  */
                     72: struct direct *
                     73: readdir(dirp)
                     74: register DIR *dirp;
                     75: {
                     76:        register struct olddirect *dp;
                     77:        static struct direct dir;
                     78: 
                     79:        for (;;) {
                     80:                if (dirp->dd_loc == 0) {
                     81:                        dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
                     82:                            DIRBLKSIZ);
                     83:                        if (dirp->dd_size <= 0)
                     84:                                return NULL;
                     85:                }
                     86:                if (dirp->dd_loc >= dirp->dd_size) {
                     87:                        dirp->dd_loc = 0;
                     88:                        continue;
                     89:                }
                     90:                dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc);
                     91:                dirp->dd_loc += sizeof(struct olddirect);
                     92:                if (dp->od_ino == 0)
                     93:                        continue;
                     94:                dir.d_ino = dp->od_ino;
                     95:                strncpy(dir.d_name, dp->od_name, ODIRSIZ);
                     96:                dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
                     97:                dir.d_namlen = strlen(dir.d_name);
                     98:                dir.d_reclen = DIRSIZ(&dir);
                     99:                return (&dir);
                    100:        }
                    101: }
                    102: 
                    103: /*
                    104:  * close a directory.
                    105:  */
                    106: void
                    107: closedir(dirp)
                    108: register DIR *dirp;
                    109: {
                    110:        close(dirp->dd_fd);
                    111:        dirp->dd_fd = -1;
                    112:        dirp->dd_loc = 0;
                    113:        free(dirp);
                    114: }
                    115: #endif USENDIR

unix.superglobalmegacorp.com

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