Annotation of 43BSDReno/contrib/isode-beta/dirent/testdir.c, revision 1.1

1.1     ! root        1: /*
        !             2:        testdir -- basic test for C library directory access routines
        !             3: 
        !             4:        last edit:      25-Apr-1987     D A Gwyn
        !             5: */
        !             6: 
        !             7: #include       <sys/types.h>
        !             8: #include       <stdio.h>
        !             9: #include       "usr.dirent.h"
        !            10: 
        !            11: extern void    exit();
        !            12: extern int     strcmp();
        !            13: 
        !            14: main( argc, argv )
        !            15:        int                     argc;
        !            16:        register char           **argv;
        !            17:        {
        !            18:        register DIR            *dirp;
        !            19:        register struct dirent  *dp;
        !            20:        int                     nerrs = 0;      /* total not found */
        !            21: 
        !            22:        if ( (dirp = opendir( "." )) == NULL )
        !            23:                {
        !            24:                (void)fprintf( stderr, "Cannot open \".\" directory\n" );
        !            25:                exit( 1 );
        !            26:                }
        !            27: 
        !            28:        if (argc == 1) {
        !            29:            while (dp = readdir (dirp))
        !            30:                printf ("ino=%d len=%d name=\"%s\"\n",
        !            31:                        dp -> d_ino, strlen (dp -> d_name), dp -> d_name);
        !            32:            (void) closedir (dirp);
        !            33:            exit (0);
        !            34:        }
        !            35:        
        !            36:        while ( --argc > 0 )
        !            37:                {
        !            38:                ++argv;
        !            39: 
        !            40:                while ( (dp = readdir( dirp )) != NULL )
        !            41:                        if ( strcmp( dp->d_name, *argv ) == 0 )
        !            42:                                {
        !            43:                                (void)printf( "\"%s\" found.\n", *argv );
        !            44:                                break;
        !            45:                                }
        !            46: 
        !            47:                if ( dp == NULL )
        !            48:                        {
        !            49:                        (void)printf( "\"%s\" not found.\n", *argv );
        !            50:                        ++nerrs;
        !            51:                        }
        !            52: 
        !            53:                rewinddir( dirp );
        !            54:                }
        !            55: 
        !            56:        (void)closedir( dirp );
        !            57:        exit( nerrs );
        !            58:        }

unix.superglobalmegacorp.com

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