home *** CD-ROM | disk | FTP | other *** search
- /* dirtest.c (c) Copyright 1990 H.Rogers */
-
- /* This program tests the directory(3) library routines. */
- /* For full information on these, read the appropriate entry
- * in section 3 of the UNIX Programmer's Manual. */
-
- #include <stdio.h> /* standard I/O */
- #include <stdlib.h> /* standard library */
- #include <string.h> /* standard string library */
-
- #include "unistd.h" /* UNIX system calls */
- #include "dirent.h" /* directory handling functions */
- #include "sys/stat.h" /* file status */
-
- int
- main (argc, argv)
- int argc;
- char **argv;
- {
- DIR *dirp; /* directory pointer */
- struct dirent *d; /* directory entry structure */
- struct stat s[1]; /* file status structure */
- static char buf[256]; /* buffer */
-
- putchar ('\n');
-
- while (++argv, --argc) /* cycle through arguments */
- {
- if (!(dirp = opendir (*argv))) /* open directory */
- {
- printf ("dirtest: could not open directory %s\n\n", *argv);
- continue;
- }
- printf ("directory: %s\n\n", *argv);
- while (d = readdir (dirp)) /* read directory entry */
- {
- sprintf (buf, "%s/%s", *argv, d->d_name);
- stat (buf, s); /* get file status */
- printf ("%8o %s\n", s->st_mode, d->d_name); /* print file mode & name */
- }
- closedir (dirp); /* close directory */
- putchar ('\n');
- }
- return 0;
- }
-