test.cxx 738 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #ifdef _WIN32
  4. #include <io.h>
  5. #else
  6. #include <unistd.h>
  7. #endif
  8. // return true if the file exists
  9. int FileExists(const char* filename)
  10. {
  11. #ifdef _MSC_VER
  12. #define access _access
  13. #endif
  14. #ifndef F_OK
  15. #define F_OK 0
  16. #endif
  17. if (access(filename, F_OK) != 0) {
  18. return false;
  19. } else {
  20. return true;
  21. }
  22. }
  23. int main(int ac, char** av)
  24. {
  25. if (ac <= 1) {
  26. printf("Usage: %s <file>\n", av[0]);
  27. return 1;
  28. }
  29. if (!FileExists(av[1])) {
  30. printf("Missing file %s\n", av[1]);
  31. return 1;
  32. }
  33. if (FileExists(av[2])) {
  34. printf("File %s should be in subdirectory\n", av[2]);
  35. return 1;
  36. }
  37. printf("%s is not there! Good.", av[2]);
  38. printf("%s is there! Good.", av[1]);
  39. return 0;
  40. }