diff --git a/.gitignore b/.gitignore index 6294dc4..babf41b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ # Prerequisites +build *._* *.d diff --git a/plugins/utils.c b/plugins/utils.c index dfdbcf6..bce7636 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -335,12 +335,27 @@ unsigned simple_hash(const char* key) hashval = *key + 31 * hashval; return hashval; } -int is_file(const char* f) +int _exist(const char* f) { struct stat st; return !(stat(f, &st) == -1); } - +int is_file(const char* f) +{ + int st = is_dir(f); + if(st == -1) return -1; + else return st==0; +} +int is_dir(const char* f) +{ + struct stat st; + if(stat(f, &st) == -1) + return -1; // unknow + else if(st.st_mode & S_IFDIR) + return 1; + else + return 0; +} // These vars will contain the hash void md5(uint8_t *initial_msg, size_t initial_len, char* buff) { diff --git a/plugins/utils.h b/plugins/utils.h index e765f86..e243e54 100644 --- a/plugins/utils.h +++ b/plugins/utils.h @@ -86,6 +86,8 @@ char to_hex(char code); unsigned hash(const char*, int); unsigned simple_hash(const char*); int is_file(const char* f); +int is_dir(const char* f); +int _exist(const char* f); void md5(uint8_t *, size_t , char*); void sha1(const char*, char*); #endif