Add FILEPATH_HOME
This commit is contained in:
parent
fc0f657774
commit
fce41edbe5
15
src/file_t.c
15
src/file_t.c
@ -32,6 +32,15 @@ file_init(const char *filename, filepath_t FILEPATH, exception_t *e)
|
||||
switch (FILEPATH) {
|
||||
case FILEPATH_ABSOLUTE: {
|
||||
realpath(filename, path);
|
||||
break;
|
||||
}
|
||||
case FILEPATH_HOME: {
|
||||
char* home = getenv("HOME");
|
||||
size_t pathlen = strlen(home) + strlen(filename);
|
||||
path = malloc(pathlen + 1);
|
||||
strcpy(home, path);
|
||||
strcat(path, filename);
|
||||
path[pathlen] = '\0';
|
||||
}
|
||||
case FILEPATH_RELATIVE: path = (char*) filename; break;
|
||||
}
|
||||
@ -55,7 +64,11 @@ file_init(const char *filename, filepath_t FILEPATH, exception_t *e)
|
||||
void
|
||||
file_close(file_t *f)
|
||||
{
|
||||
if (f->fp == FILEPATH_ABSOLUTE) free(f->name);
|
||||
switch (f->fp) {
|
||||
case FILEPATH_ABSOLUTE:
|
||||
case FILEPATH_HOME: free(f->name);
|
||||
default: break;
|
||||
}
|
||||
if (f->hash_str != NULL) free(f->hash_str);
|
||||
free(f);
|
||||
}
|
||||
|
@ -7,7 +7,8 @@
|
||||
|
||||
typedef enum filepath_t {
|
||||
FILEPATH_ABSOLUTE,
|
||||
FILEPATH_RELATIVE
|
||||
FILEPATH_RELATIVE,
|
||||
FILEPATH_HOME
|
||||
} filepath_t;
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user