Changes for compiling on Illumos

* common.mk: use -lsocket -liconv -lgen on Illumos/Solaris
* mkdirp: return int and accept a mode argument
* use i3's mkdirp on everything except Illumos
This commit is contained in:
Tim Creech
2015-07-27 20:47:12 -04:00
committed by Tim Creech
parent c8b4303eff
commit f41018b33e
6 changed files with 26 additions and 15 deletions

View File

@ -8,24 +8,26 @@
* 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 !defined(__sun)
int mkdirp(const char *path, mode_t mode) {
if (mkdir(path, mode) == 0)
return 0;
if (errno == EEXIST) {
struct stat st;
/* Check that the named file actually is a directory. */
if (stat(path, &st)) {
ELOG("stat(%s) failed: %s\n", path, strerror(errno));
return false;
return -1;
}
if (!S_ISDIR(st.st_mode)) {
ELOG("mkdir(%s) failed: %s\n", path, strerror(ENOTDIR));
return false;
return -1;
}
return true;
return 0;
} else if (errno != ENOENT) {
ELOG("mkdir(%s) failed: %s\n", path, strerror(errno));
return false;
return -1;
}
char *copy = sstrdup(path);
/* strip trailing slashes, if any */
@ -38,13 +40,14 @@ bool mkdirp(const char *path) {
free(copy);
copy = NULL;
}
return false;
return -1;
}
*sep = '\0';
bool result = false;
if (mkdirp(copy))
result = mkdirp(path);
int result = -1;
if (mkdirp(copy, mode) == 0)
result = mkdirp(path, mode);
free(copy);
return result;
}
#endif