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

1.1       root        1: /*     @(#)stat.c      1.2 90/01/03 NFS Rev 2 Testsuite
                      2:  *     1.4 Lachman ONC Test Suite source
                      3:  *
                      4:  * stat all of the files in a directory tree
                      5:  */
                      6: #include       <stdio.h>
                      7: #include       <sys/types.h>
                      8: #include       <sys/stat.h>
                      9: #ifdef SVR3
                     10: #include       <sys/fs/nfs/time.h>
                     11: #include       <dirent.h>
                     12: #else
                     13: #include       <sys/time.h>
                     14: #include       <sys/dir.h>
                     15: #endif
                     16: 
                     17: int stats = 0;
                     18: int readdirs = 0;
                     19: 
                     20: main(argc, argv)
                     21:        int argc;
                     22:        char *argv[];
                     23: {
                     24:        struct timeval stim, etim;
                     25:        float elapsed;
                     26: 
                     27:        if (argc != 2) {
                     28:                fprintf(stderr, "usage: %s dir\n", argv[0]);
                     29:                exit(1);
                     30:        }
                     31: 
                     32:        gettimeofday(&stim, 0);
                     33:        statit(argv[1]);
                     34:        gettimeofday(&etim, 0);
                     35:        elapsed = (float) (etim.tv_sec - stim.tv_sec) +
                     36:            (float)(etim.tv_usec - stim.tv_usec) / 1000000.0;
                     37:        fprintf(stdout, "%d calls in %f seconds (%f calls/sec)\n",
                     38:            stats, elapsed, (float)stats / elapsed);
                     39:        exit(0);
                     40: }
                     41: 
                     42: statit(name)
                     43:        char *name;
                     44: {
                     45:        struct stat statb;
                     46: #ifdef SVR3
                     47:        struct dirent *di;
                     48: #else
                     49:        struct direct *di;
                     50: #endif
                     51:        DIR *dirp;
                     52:        long loc;
                     53: 
                     54: #ifdef SVR3
                     55:        if (stat(name, &statb) < 0) {
                     56: #else
                     57:        if (lstat(name, &statb) < 0) {
                     58: #endif
                     59:                perror(name);
                     60:        }
                     61:        if ((statb.st_mode & S_IFMT) != S_IFDIR) {
                     62:                return;
                     63:        }
                     64: 
                     65:        if ((dirp = opendir(name)) == NULL) {
                     66:                perror(name);
                     67:                return;
                     68:        }
                     69:        stats++;
                     70:        chdir(name);
                     71: 
                     72:        while ((di = readdir(dirp)) != NULL) {
                     73:                if (strcmp(di->d_name, ".") == 0 || strcmp(di->d_name, "..") == 0)
                     74:                    continue;
                     75: #ifdef SVR3
                     76:                if (stat(di->d_name, &statb) < 0) {
                     77: #else
                     78:                if (lstat(di->d_name, &statb) < 0) {
                     79: #endif
                     80:                        perror(di->d_name);
                     81:                }
                     82:                stats++;
                     83:                if ((statb.st_mode & S_IFMT) == S_IFDIR) {
                     84:                        loc = telldir(dirp);
                     85:                        closedir(dirp);
                     86:                        statit(di->d_name);
                     87:                        if ((dirp = opendir(".")) == NULL) {
                     88:                                perror(name);
                     89:                                chdir("..");
                     90:                                return;
                     91:                        }
                     92:                        seekdir(dirp, loc);
                     93:                }
                     94:        }
                     95:        chdir("..");
                     96:        return;
                     97: }

unix.superglobalmegacorp.com

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