mirror of
https://github.com/irssi/irssi.git
synced 2025-01-03 14:56:47 -05:00
mkpath() - behaves like mkdir -p. Autologging now uses it to create
log directories. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@591 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
308e84bbc4
commit
6675cec459
@ -337,6 +337,39 @@ int regexp_match(const char *str, const char *regexp)
|
|||||||
return ret == 0;
|
return ret == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Create the directory and all it's parent directories */
|
||||||
|
int mkpath(const char *path, int mode)
|
||||||
|
{
|
||||||
|
struct stat statbuf;
|
||||||
|
const char *p;
|
||||||
|
char *dir;
|
||||||
|
|
||||||
|
g_return_val_if_fail(path != NULL, -1);
|
||||||
|
|
||||||
|
p = g_path_skip_root((char *) path);
|
||||||
|
for (;;) {
|
||||||
|
if (*p != G_DIR_SEPARATOR && *p != '\0') {
|
||||||
|
p++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
dir = g_strndup(path, (int) (p-path));
|
||||||
|
if (stat(dir, &statbuf) != 0) {
|
||||||
|
if (mkdir(dir, mode) == -1) {
|
||||||
|
g_free(dir);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_free(dir);
|
||||||
|
|
||||||
|
if (*p++ == '\0')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* convert ~/ to $HOME */
|
||||||
char *convert_home(const char *path)
|
char *convert_home(const char *path)
|
||||||
{
|
{
|
||||||
return *path == '~' && (*(path+1) == '/' || *(path+1) == '\0') ?
|
return *path == '~' && (*(path+1) == '/' || *(path+1) == '\0') ?
|
||||||
|
@ -41,6 +41,9 @@ char *stristr_full(const char *data, const char *key);
|
|||||||
/* easy way to check if regexp matches */
|
/* easy way to check if regexp matches */
|
||||||
int regexp_match(const char *str, const char *regexp);
|
int regexp_match(const char *str, const char *regexp);
|
||||||
|
|
||||||
|
/* Create the directory and all it's parent directories */
|
||||||
|
int mkpath(const char *path, int mode);
|
||||||
|
/* convert ~/ to $HOME */
|
||||||
char *convert_home(const char *path);
|
char *convert_home(const char *path);
|
||||||
|
|
||||||
/* Case-insensitive string hash functions */
|
/* Case-insensitive string hash functions */
|
||||||
|
@ -306,7 +306,7 @@ static void autolog_log(void *server, const char *target)
|
|||||||
dir = g_dirname(str);
|
dir = g_dirname(str);
|
||||||
g_free(str);
|
g_free(str);
|
||||||
|
|
||||||
mkdir(dir, LOG_DIR_CREATE_MODE);
|
mkpath(dir, LOG_DIR_CREATE_MODE);
|
||||||
g_free(dir);
|
g_free(dir);
|
||||||
|
|
||||||
log = log_create_rec(fname, autolog_level, target);
|
log = log_create_rec(fname, autolog_level, target);
|
||||||
|
Loading…
Reference in New Issue
Block a user