home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / unixlib / !UnixLib / test / c / dirtest < prev    next >
Encoding:
Text File  |  1994-03-08  |  1.3 KB  |  46 lines

  1. /* dirtest.c (c) Copyright 1990 H.Rogers */
  2.  
  3. /* This program tests the directory(3) library routines. */
  4. /* For full information on these, read the appropriate entry
  5.  * in section 3 of the UNIX Programmer's Manual. */
  6.  
  7. #include <stdio.h>        /* standard I/O */
  8. #include <stdlib.h>        /* standard library */
  9. #include <string.h>        /* standard string library */
  10.  
  11. #include "unistd.h"        /* UNIX system calls */
  12. #include "dirent.h"        /* directory handling functions */
  13. #include "sys/stat.h"        /* file status */
  14.  
  15. int
  16. main (argc, argv)
  17.      int argc;
  18.      char **argv;
  19. {
  20.   DIR *dirp;            /* directory pointer */
  21.   struct dirent *d;        /* directory entry structure */
  22.   struct stat s[1];        /* file status structure */
  23.   static char buf[256];        /* buffer */
  24.  
  25.   putchar ('\n');
  26.  
  27.   while (++argv, --argc)    /* cycle through arguments */
  28.     {
  29.       if (!(dirp = opendir (*argv)))    /* open directory */
  30.     {
  31.       printf ("dirtest: could not open directory %s\n\n", *argv);
  32.       continue;
  33.     }
  34.       printf ("directory: %s\n\n", *argv);
  35.       while (d = readdir (dirp))    /* read directory entry */
  36.     {
  37.       sprintf (buf, "%s/%s", *argv, d->d_name);
  38.       stat (buf, s);    /* get file status */
  39.       printf ("%8o  %s\n", s->st_mode, d->d_name);    /* print file mode & name */
  40.     }
  41.       closedir (dirp);        /* close directory */
  42.       putchar ('\n');
  43.     }
  44.   return 0;
  45. }
  46.