43 lines
746 B
C++
Raw Normal View History

#include <stdio.h>
2016-07-09 11:21:54 +02:00
#include <stdlib.h>
#ifdef _WIN32
2018-08-09 18:06:22 +02:00
# include <io.h>
#else
2018-08-09 18:06:22 +02:00
# include <unistd.h>
#endif
// return true if the file exists
int FileExists(const char* filename)
{
#ifdef _MSC_VER
2018-08-09 18:06:22 +02:00
# define access _access
#endif
#ifndef F_OK
2018-08-09 18:06:22 +02:00
# define F_OK 0
#endif
2016-07-09 11:21:54 +02:00
if (access(filename, F_OK) != 0) {
return false;
2016-07-09 11:21:54 +02:00
} else {
return true;
2016-07-09 11:21:54 +02:00
}
}
int main(int ac, char** av)
{
2016-07-09 11:21:54 +02:00
if (ac <= 1) {
printf("Usage: %s <file>\n", av[0]);
return 1;
2016-07-09 11:21:54 +02:00
}
if (!FileExists(av[1])) {
printf("Missing file %s\n", av[1]);
return 1;
2016-07-09 11:21:54 +02:00
}
if (FileExists(av[2])) {
printf("File %s should be in subdirectory\n", av[2]);
return 1;
2016-07-09 11:21:54 +02:00
}
printf("%s is not there! Good.", av[2]);
printf("%s is there! Good.", av[1]);
return 0;
}