[Add] Create ~/.lephisto/conf if not found. Though, leave it empty.

This commit is contained in:
Allanis 2014-03-10 22:56:34 +00:00
parent 37d3e8ec1e
commit deb76abd8d
3 changed files with 33 additions and 1 deletions

View File

@ -283,8 +283,9 @@ int conf_loadConfig(const char* file) {
}
} else {
/* Failed to load the config file.. */
DEBUG("Config file '%s' not found.", file);
lua_close(L);
DEBUG("Config file '%s' not found.", file);
lfile_touch(file);
return 1;
}
lua_close(L);

View File

@ -244,3 +244,32 @@ char** lfile_readDir(int* lfiles, const char* path, ...) {
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;
}

View File

@ -10,3 +10,5 @@ int lfile_fileExists(const char* path, ...);
char** lfile_readDir(int* lfiles, const char* path, ...);
int lfile_touch(const char* path, ...);