[net.sources.bugs] Fix to find directory

rlk@mit-trillian.MIT.EDU (Robert L Krawitz) (08/14/86)

I goofed a little -- forgot to check stat's status.  So giving a bogus
pathname following a directory will return the broken path as well.
Here's the fix.

/* fd -- echo arguments that are directories */
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>

struct stat stats;

main(argc,argv)
     int argc;
     char **argv;
{
  char *file;
  argc--;
  argv++;
  while (argc > 0)
    {
      file = *argv;
      if (stat(file, &stats) == 0)
	if (((stats.st_mode) & S_IFMT) == S_IFDIR) printf ("%s\n", file);
      argc--;
      argv++;
    }
}
-- 
Robert^Z