home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / VRAC / CUJJUN93.ZIP / 1106132A < prev    next >
Text File  |  1993-04-01  |  978b  |  49 lines

  1. /* list.c:  Print a directory listing */
  2.  
  3. #include <stdio.h>
  4. #include <dirent.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <time.h>
  8. #include <string.h>
  9. #include <assert.h>
  10.  
  11. static char *attr_str(short attr);
  12.  
  13. main()
  14. {
  15.     DIR *dirp = opendir(".");  /* Current dir */
  16.     struct dirent *entry;
  17.     struct stat finfo;
  18.  
  19.     assert(dirp);
  20.     while ((entry = readdir(dirp)) != NULL)
  21.     {
  22.         stat(entry->d_name,&finfo);
  23.         printf(
  24.                "%-12.12s   %s %8ld  %s",
  25.                strlwr(entry->d_name),
  26.                attr_str(finfo.st_mode),
  27.                finfo.st_size,
  28.                ctime(&finfo.st_mtime)
  29.               );
  30.     }
  31.     closedir(dirp);
  32.     return 0;
  33. }
  34.  
  35. static char *attr_str(short attr)
  36. {
  37.     static char s[4];
  38.     
  39.     strcpy(s,"---");
  40.     if (attr & S_IFDIR)
  41.         s[0] = 'd';
  42.     if (attr & S_IREAD)
  43.         s[1] = 'r';
  44.     if (attr & S_IWRITE)
  45.         s[2] = 'w';
  46.     return s;
  47. }
  48.  
  49.