mirror of
https://github.com/ptitSeb/box86.git
synced 2024-11-27 20:04:16 +08:00
More check of executable file
This commit is contained in:
parent
fd8aff098f
commit
25b3b57564
@ -14,12 +14,23 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "fileutils.h"
|
#include "fileutils.h"
|
||||||
|
|
||||||
int FileExist(const char* filename)
|
int FileExist(const char* filename, int flags)
|
||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
if (stat(filename, &sb) == -1)
|
if (stat(filename, &sb) == -1)
|
||||||
return 0;
|
return 0;
|
||||||
// check type of file? should be executable, or folder
|
// 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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,7 +40,7 @@ char* ResolveFile(const char* filename, path_collection_t* paths)
|
|||||||
for (int i=0; i<paths->size; ++i) {
|
for (int i=0; i<paths->size; ++i) {
|
||||||
strcpy(p, paths->paths[i]);
|
strcpy(p, paths->paths[i]);
|
||||||
strcat(p, filename);
|
strcat(p, filename);
|
||||||
if(FileExist(p))
|
if(FileExist(p, IS_FILE))
|
||||||
return strdup(p);
|
return strdup(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,11 @@
|
|||||||
|
|
||||||
#include "pathcoll.h"
|
#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
|
char* ResolveFile(const char* filename, path_collection_t* paths); // find a file, using Path if needed
|
||||||
|
|
||||||
#endif //__FILEUTILS_H_
|
#endif //__FILEUTILS_H_
|
@ -90,7 +90,7 @@ int main(int argc, const char **argv) {
|
|||||||
FreeBox86Context(&context);
|
FreeBox86Context(&context);
|
||||||
return -1;
|
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]);
|
printf_debug(DEBUG_NONE, "Error, file is not found\n", context->argv[0]);
|
||||||
FreeBox86Context(&context);
|
FreeBox86Context(&context);
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user