1
0

test.cxx 772 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. {
  19. return false;
  20. }
  21. else
  22. {
  23. return true;
  24. }
  25. }
  26. int main(int ac, char** av)
  27. {
  28. if(ac <= 1)
  29. {
  30. printf("Usage: %s <file>\n", av[0]);
  31. return 1;
  32. }
  33. if(!FileExists(av[1]))
  34. {
  35. printf("Missing file %s\n", av[1]);
  36. return 1;
  37. }
  38. if(FileExists(av[2]))
  39. {
  40. printf("File %s should be in subdirectory\n", av[2]);
  41. return 1;
  42. }
  43. printf("%s is not there! Good.", av[2]);
  44. printf("%s is there! Good.", av[1]);
  45. return 0;
  46. }