home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume9 / gwyn-dir-lib / testdir.c < prev   
Encoding:
C/C++ Source or Header  |  1987-04-30  |  837 b   |  51 lines

  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    <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.     while ( --argc > 0 )
  29.         {
  30.         ++argv;
  31.  
  32.         while ( (dp = readdir( dirp )) != NULL )
  33.             if ( strcmp( dp->d_name, *argv ) == 0 )
  34.                 {
  35.                 (void)printf( "\"%s\" found.\n", *argv );
  36.                 break;
  37.                 }
  38.  
  39.         if ( dp == NULL )
  40.             {
  41.             (void)printf( "\"%s\" not found.\n", *argv );
  42.             ++nerrs;
  43.             }
  44.  
  45.         rewinddir( dirp );
  46.         }
  47.  
  48.     (void)closedir( dirp );
  49.     exit( nerrs );
  50.     }
  51.