Fixed error output on nonexistent file

This commit is contained in:
rexy712 2019-09-16 16:16:14 -07:00
parent e3586a9e93
commit ca79f26d4e

View File

@ -141,16 +141,25 @@ void nonprinting_notation(int in, char* dest){
bool is_directory(const char* file){
struct stat st;
if(stat(file, &st) != 0){
return true;
return false;
}
return S_ISDIR(st.st_mode);
}
bool file_exists(const char* file){
struct stat st;
return stat(file, &st) == 0;
}
FILE* open_file(const char* file, const char* mode){
if(is_directory(file)){
fflush(stdout);
fprintf(stderr, "Unable to open file \"%s\": Is a directory \n", file);
return nullptr;
}
if(!file_exists(file)){
fflush(stdout);
fprintf(stderr, "Unable to open file \"%s\": No such file\n", file);
return nullptr;
}
FILE* fp = fopen(file, mode);
if(!fp){
fflush(stdout);