[Add] Create ~/.lephisto/conf if not found. Though, leave it empty.
This commit is contained in:
parent
37d3e8ec1e
commit
deb76abd8d
@ -283,8 +283,9 @@ int conf_loadConfig(const char* file) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Failed to load the config file.. */
|
/* Failed to load the config file.. */
|
||||||
DEBUG("Config file '%s' not found.", file);
|
|
||||||
lua_close(L);
|
lua_close(L);
|
||||||
|
DEBUG("Config file '%s' not found.", file);
|
||||||
|
lfile_touch(file);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
lua_close(L);
|
lua_close(L);
|
||||||
|
29
src/lfile.c
29
src/lfile.c
@ -244,3 +244,32 @@ char** lfile_readDir(int* lfiles, const char* path, ...) {
|
|||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Tries to create the file if it doesn't exist.
|
||||||
|
* @param path Path of the file to create.
|
||||||
|
*/
|
||||||
|
int lfile_touch(const char* path, ...) {
|
||||||
|
char file[PATH_MAX];
|
||||||
|
va_list ap;
|
||||||
|
size_t l;
|
||||||
|
FILE* f;
|
||||||
|
|
||||||
|
l = 0;
|
||||||
|
if(path == NULL) return -1;
|
||||||
|
else { /* Get the message. */
|
||||||
|
va_start(ap, path);
|
||||||
|
vsnprintf(file, PATH_MAX-l, path, ap);
|
||||||
|
l = strlen(file);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Try to open the file, C89 cmpliant, but not as precise as stat. */
|
||||||
|
f = fopen(file, "a+");
|
||||||
|
if(f == NULL) {
|
||||||
|
WARN("Unable to touch file '%s': %s", file, strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -10,3 +10,5 @@ int lfile_fileExists(const char* path, ...);
|
|||||||
|
|
||||||
char** lfile_readDir(int* lfiles, const char* path, ...);
|
char** lfile_readDir(int* lfiles, const char* path, ...);
|
||||||
|
|
||||||
|
int lfile_touch(const char* path, ...);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user