Fixed error output on nonexistent file
This commit is contained in:
parent
e3586a9e93
commit
ca79f26d4e
@ -141,16 +141,25 @@ void nonprinting_notation(int in, char* dest){
|
|||||||
bool is_directory(const char* file){
|
bool is_directory(const char* file){
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if(stat(file, &st) != 0){
|
if(stat(file, &st) != 0){
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
return S_ISDIR(st.st_mode);
|
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){
|
FILE* open_file(const char* file, const char* mode){
|
||||||
if(is_directory(file)){
|
if(is_directory(file)){
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
fprintf(stderr, "Unable to open file \"%s\": Is a directory \n", file);
|
fprintf(stderr, "Unable to open file \"%s\": Is a directory \n", file);
|
||||||
return nullptr;
|
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);
|
FILE* fp = fopen(file, mode);
|
||||||
if(!fp){
|
if(!fp){
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user