home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emx / test / ftwtest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  1.1 KB  |  63 lines

  1. /* ftwtest.c (emx+gcc) */
  2.  
  3. #include <stdio.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <ftw.h>
  7.  
  8. static char *pmode (int m)
  9. {
  10.   static char buf[16], *p;
  11.   int i, n;
  12.  
  13.   switch (m & S_IFMT)
  14.     {
  15.     case S_IFREG:
  16.       buf[0] = ' ';
  17.       break;
  18.     case S_IFDIR:
  19.       buf[0] = 'd';
  20.       break;
  21.     default:
  22.       buf[0] = '?';
  23.       break;
  24.     }
  25.   p = buf+1; n = m & 0777;
  26.   for (i = 0; i < 3; ++i)
  27.     {
  28.       *p++ = (n & S_IREAD  ? 'r' : '-');
  29.       *p++ = (n & S_IWRITE ? 'w' : '-');
  30.       *p++ = (n & S_IEXEC  ? 'x' : '-');
  31.       n <<= 3;
  32.     }
  33.   buf[10] = 0;
  34.   return (buf);
  35. }
  36.  
  37.  
  38. static int walker (const char *name, const struct stat *st, int flag)
  39. {
  40.   if (flag == FTW_NS)
  41.     printf ("           %s\n", name);
  42.   else
  43.     printf ("%s %s\n", pmode ((int)st->st_mode), name);
  44.   return (0);
  45. }
  46.  
  47.  
  48. int main (int argc, char *argv[])
  49. {
  50.   int i, rc;
  51.  
  52.   for (i = 1; i < argc; ++i)
  53.     {
  54.       rc = ftw (argv[i], walker, 10);
  55.       if (rc < 0)
  56.         {
  57.           perror (argv[i]);
  58.           return (1);
  59.         }
  60.     }
  61.   return (0);
  62. }
  63.