Add absolute paths to file_t
This commit is contained in:
parent
0794691f5a
commit
f9f8ce747a
21
src/file_t.c
21
src/file_t.c
@ -28,10 +28,10 @@ get_size_by_fd(int fd)
|
|||||||
file_t*
|
file_t*
|
||||||
file_init(const char *filename, filepath_t FILEPATH, exception_t *e)
|
file_init(const char *filename, filepath_t FILEPATH, exception_t *e)
|
||||||
{
|
{
|
||||||
char *path;
|
char *path = NULL;
|
||||||
switch (FILEPATH) {
|
switch (FILEPATH) {
|
||||||
case FILEPATH_ABSOLUTE: {
|
case FILEPATH_ABSOLUTE: {
|
||||||
path = (char*) filename; break;
|
realpath(filename, path);
|
||||||
}
|
}
|
||||||
case FILEPATH_RELATIVE: path = (char*) filename; break;
|
case FILEPATH_RELATIVE: path = (char*) filename; break;
|
||||||
}
|
}
|
||||||
@ -46,14 +46,16 @@ file_init(const char *filename, filepath_t FILEPATH, exception_t *e)
|
|||||||
|
|
||||||
file_t *f;
|
file_t *f;
|
||||||
f = malloc(sizeof(file_t));
|
f = malloc(sizeof(file_t));
|
||||||
f->name = (char*) path;
|
f->name = path;
|
||||||
f->hash_str = NULL;
|
f->hash_str = NULL;
|
||||||
|
f->fp = FILEPATH;
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
file_close(file_t *f)
|
file_close(file_t *f)
|
||||||
{
|
{
|
||||||
|
if (f->fp == FILEPATH_ABSOLUTE) free(f->name);
|
||||||
if (f->hash_str != NULL) free(f->hash_str);
|
if (f->hash_str != NULL) free(f->hash_str);
|
||||||
free(f);
|
free(f);
|
||||||
}
|
}
|
||||||
@ -100,3 +102,16 @@ file_md5_str(file_t *f, exception_t *e)
|
|||||||
f->hash_str[2*MD5_DIGEST_LENGTH] = '\0';
|
f->hash_str[2*MD5_DIGEST_LENGTH] = '\0';
|
||||||
return f->hash_str;
|
return f->hash_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
file_abs(const file_t *f) {
|
||||||
|
char *path = NULL;
|
||||||
|
switch (f->fp) {
|
||||||
|
case FILEPATH_ABSOLUTE: return f->name;
|
||||||
|
case FILEPATH_RELATIVE: {
|
||||||
|
realpath(f->name, path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
@ -17,6 +17,7 @@ typedef struct file_t {
|
|||||||
char *name; /**< Absolute path to file */
|
char *name; /**< Absolute path to file */
|
||||||
unsigned char hash[MD5_DIGEST_LENGTH]; /**< MD5sum hash */
|
unsigned char hash[MD5_DIGEST_LENGTH]; /**< MD5sum hash */
|
||||||
char *hash_str; /**< MD5sum hash as char* */
|
char *hash_str; /**< MD5sum hash as char* */
|
||||||
|
filepath_t fp;
|
||||||
} file_t;
|
} file_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,4 +52,7 @@ file_md5_gen(file_t *f, exception_t *e);
|
|||||||
char*
|
char*
|
||||||
file_md5_str(file_t *f, exception_t *e);
|
file_md5_str(file_t *f, exception_t *e);
|
||||||
|
|
||||||
|
char*
|
||||||
|
file_abs(const file_t *f);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user