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