add utils functions

This commit is contained in:
lxsang 2016-12-15 14:46:50 +01:00
parent 22fa1a6338
commit a49dd2c090
3 changed files with 20 additions and 2 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
# Prerequisites # Prerequisites
build
*._* *._*
*.d *.d

View File

@ -335,12 +335,27 @@ unsigned simple_hash(const char* key)
hashval = *key + 31 * hashval; hashval = *key + 31 * hashval;
return hashval; return hashval;
} }
int is_file(const char* f) int _exist(const char* f)
{ {
struct stat st; struct stat st;
return !(stat(f, &st) == -1); 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 // These vars will contain the hash
void md5(uint8_t *initial_msg, size_t initial_len, char* buff) { void md5(uint8_t *initial_msg, size_t initial_len, char* buff) {

View File

@ -86,6 +86,8 @@ char to_hex(char code);
unsigned hash(const char*, int); unsigned hash(const char*, int);
unsigned simple_hash(const char*); unsigned simple_hash(const char*);
int is_file(const char* f); 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 md5(uint8_t *, size_t , char*);
void sha1(const char*, char*); void sha1(const char*, char*);
#endif #endif