diff --git a/src/fileutils.c b/src/fileutils.c index 25f61f95..f2c5154f 100755 --- a/src/fileutils.c +++ b/src/fileutils.c @@ -14,12 +14,23 @@ #include "debug.h" #include "fileutils.h" -int FileExist(const char* filename) +int FileExist(const char* filename, int flags) { struct stat sb; if (stat(filename, &sb) == -1) return 0; // check type of file? should be executable, or folder + if(flags&IS_FILE) { + if(!S_ISREG(sb.st_mode)) + return 0; + } else { + if(!S_ISDIR(sb.st_mode)) + return 0; + } + if(flags&IS_EXECUTABLE) { + if(sb.st_mode&S_IXUSR!=S_IXUSR) + return 0; // nope + } return 1; } @@ -29,7 +40,7 @@ char* ResolveFile(const char* filename, path_collection_t* paths) for (int i=0; isize; ++i) { strcpy(p, paths->paths[i]); strcat(p, filename); - if(FileExist(p)) + if(FileExist(p, IS_FILE)) return strdup(p); } diff --git a/src/fileutils.h b/src/fileutils.h index 46833b3b..d35cfd35 100755 --- a/src/fileutils.h +++ b/src/fileutils.h @@ -3,7 +3,11 @@ #include "pathcoll.h" -int FileExist(const char* filename); // 0 : doesn't exist, 1: Does exist +#define IS_EXECUTABLE (1<<0) +#define IS_FILE (1<<1) + + +int FileExist(const char* filename, int flags); // 0 : doesn't exist, 1: Does exist char* ResolveFile(const char* filename, path_collection_t* paths); // find a file, using Path if needed #endif //__FILEUTILS_H_ \ No newline at end of file diff --git a/src/main.c b/src/main.c index 93152bb3..848a8e60 100755 --- a/src/main.c +++ b/src/main.c @@ -90,7 +90,7 @@ int main(int argc, const char **argv) { FreeBox86Context(&context); return -1; } - if(!FileExist(context->argv[0])) { + if(!FileExist(context->argv[0], IS_FILE|IS_EXECUTABLE)) { printf_debug(DEBUG_NONE, "Error, file is not found\n", context->argv[0]); FreeBox86Context(&context); return -1;