notspecial.c 675 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * check a filename to see if it's a (fifo|character special|socket) object
  3. * (if a stat() function doesn't exist, we can't stat so we'll just return
  4. * true no matter what.)
  5. */
  6. #include "config.h"
  7. #if HAVE_STAT && HAS_ISCHR && HAS_ISFIFO && HAS_ISSOCK
  8. #include <sys/stat.h>
  9. int
  10. notspecial(char *file)
  11. {
  12. struct stat info;
  13. if ( stat(file, &info) != 0 )
  14. return 1;
  15. return S_ISREG(info.st_mode);
  16. }
  17. #else
  18. int
  19. notspecial(char *file)
  20. {
  21. return 1;
  22. }
  23. #endif
  24. #if DEBUG
  25. #include <stdio.h>
  26. int
  27. main(argc, argv)
  28. char **argv;
  29. {
  30. int i;
  31. for ( i=1; i < argc; i++ )
  32. printf("%s is %sspecial\n", argv[i], notspecial(argv[i]) ? "not " : "");
  33. }
  34. #endif