Annotation of 43BSDReno/sys/nfs/TEST/unix-tests/tools/dirprt.c, revision 1.1.1.1

1.1       root        1: /*     @(#)dirprt.c    1.2 90/01/03 NFS Rev 2 Testsuite
                      2:  *     1.2 Lachman ONC Test Suite source";
                      3:  */
                      4: #include <sys/param.h>
                      5: #ifndef major
                      6: #include <sys/types.h>
                      7: #endif
                      8: #ifdef SVR3
                      9: #include <dirent.h>
                     10: #else
                     11: #include <sys/dir.h>
                     12: #endif
                     13: #include <stdio.h>
                     14: #include <ctype.h>
                     15: 
                     16: main(argc, argv)
                     17:        int argc;
                     18:        char *argv[];
                     19: {
                     20:        argv++;
                     21:        argc--;
                     22:        while (argc--) {
                     23:                print(*argv++);
                     24:        }
                     25: }
                     26: 
                     27: print(dir)
                     28:        char *dir;
                     29: {
                     30:        DIR *dirp;
                     31: #ifdef SVR3
                     32:        struct dirent *dp;
                     33: #else
                     34:        struct direct *dp;
                     35: #endif
                     36:        int rec = 0;
                     37: 
                     38:        dirp = opendir(dir);
                     39:        if (dirp == NULL) {
                     40:                perror(dir);
                     41:                return;
                     42:        }
                     43:        while ((dp = readdir(dirp)) != NULL) {
                     44: #ifdef SVR3
                     45:                printf("%5d %5ld %5d %s\n",
                     46:                    telldir(dirp),dp->d_ino, dp->d_reclen,
                     47:                    dp->d_name);
                     48: #else
                     49:                printf("%5d %5d %5d %5d %s\n",
                     50:                    telldir(dirp),dp->d_fileno, dp->d_reclen,
                     51:                    dp->d_namlen, dp->d_name);
                     52: #endif
                     53:        }
                     54:        closedir(dirp);
                     55: }
                     56: 
                     57: #include <sys/stat.h>
                     58: 
                     59: /*
                     60:  * open a directory.
                     61:  */
                     62: DIR *
                     63: opendir(name)
                     64:        char *name;
                     65: {
                     66:        register DIR *dirp;
                     67:        register int fd;
                     68:        struct stat sb;
                     69:        extern char *malloc();
                     70: 
                     71:        if ((fd = open(name, 0)) == -1) {
                     72:                printf("open failed\n");
                     73:                return (NULL);
                     74:        }
                     75:        if (fstat(fd, &sb) == -1) {
                     76:                printf("stat failed\n");
                     77:                return (NULL);
                     78:        }
                     79:        if ((sb.st_mode & S_IFMT) != S_IFDIR) {
                     80:                printf("not a directory\n");
                     81:                return (NULL);
                     82:        }
                     83:        printf("%s mode %o dir %o\n", name, sb.st_mode, S_IFDIR);
                     84:        if (((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) ||
                     85: #ifdef SVR3
                     86:            ((dirp->dd_buf = malloc(DIRBUF)) == NULL)) {
                     87: #else
                     88:            ((dirp->dd_buf = malloc((int)sb.st_blksize)) == NULL)) {
                     89: #endif
                     90:                if (dirp) {
                     91:                        if (dirp->dd_buf) {
                     92:                                free(dirp->dd_buf);
                     93:                        }
                     94:                        free(dirp);
                     95:                }
                     96:                close(fd);
                     97:                return (NULL);
                     98:        }
                     99: #ifndef SVR3
                    100:        dirp->dd_bsize = sb.st_blksize;
                    101:        dirp->dd_bbase = 0;
                    102:        dirp->dd_entno = 0;
                    103: #endif
                    104:        dirp->dd_fd = fd;
                    105:        dirp->dd_loc = 0;
                    106:        return (dirp);
                    107: }

unix.superglobalmegacorp.com

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