Move mkdirp into libi3
This commit is contained in:
30
src/ipc.c
30
src/ipc.c
@ -37,36 +37,6 @@ static void set_nonblock(int sockfd) {
|
||||
err(-1, "Could not set O_NONBLOCK");
|
||||
}
|
||||
|
||||
/*
|
||||
* Emulates mkdir -p (creates any missing folders)
|
||||
*
|
||||
*/
|
||||
bool mkdirp(const char *path) {
|
||||
if (mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0)
|
||||
return true;
|
||||
if (errno != ENOENT) {
|
||||
ELOG("mkdir(%s) failed: %s\n", path, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
char *copy = sstrdup(path);
|
||||
/* strip trailing slashes, if any */
|
||||
while (copy[strlen(copy) - 1] == '/')
|
||||
copy[strlen(copy) - 1] = '\0';
|
||||
|
||||
char *sep = strrchr(copy, '/');
|
||||
if (sep == NULL) {
|
||||
FREE(copy);
|
||||
return false;
|
||||
}
|
||||
*sep = '\0';
|
||||
bool result = false;
|
||||
if (mkdirp(copy))
|
||||
result = mkdirp(path);
|
||||
free(copy);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sends the specified event to all IPC clients which are currently connected
|
||||
* and subscribed to this kind of event.
|
||||
|
Reference in New Issue
Block a user