Output error on directory
This commit is contained in:
parent
2a733a0224
commit
49a1f0456f
@ -34,6 +34,8 @@
|
|||||||
#include <chrono> //std::chrono::*
|
#include <chrono> //std::chrono::*
|
||||||
#include <cstdlib> //srand
|
#include <cstdlib> //srand
|
||||||
#include <string> //char_traits
|
#include <string> //char_traits
|
||||||
|
#include <sys/types.h> //struct stat
|
||||||
|
#include <sys/stat.h> //struct stat
|
||||||
|
|
||||||
constexpr const char version_string[] = "roflcat version 1.0.4";
|
constexpr const char version_string[] = "roflcat version 1.0.4";
|
||||||
|
|
||||||
@ -135,11 +137,23 @@ void nonprinting_notation(int in, char* dest){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_directory(const char* file){
|
||||||
|
struct stat st;
|
||||||
|
if(stat(file, &st) != 0){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return S_ISDIR(st.st_mode);
|
||||||
|
}
|
||||||
FILE* open_file(const char* file, const char* mode){
|
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;
|
||||||
|
}
|
||||||
FILE* fp = fopen(file, mode);
|
FILE* fp = fopen(file, mode);
|
||||||
if(!fp){
|
if(!fp){
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
fprintf(stderr, "Unable to open file %s\n", file);
|
fprintf(stderr, "Unable to open file for reading: \"%s\"\n", file);
|
||||||
}
|
}
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user