From: Tim Creech Date: Tue, 28 Jul 2015 00:47:12 +0000 (-0400) Subject: Changes for compiling on Illumos X-Git-Tag: 4.11~57^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f41018b33e28bde0c02af28650a4986082f3361d;p=i3%2Fi3 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 --- diff --git a/common.mk b/common.mk index c568fb60..d2875042 100644 --- a/common.mk +++ b/common.mk @@ -178,6 +178,10 @@ else ifneq ($(UNAME),OpenBSD) LIBS += -lrt endif +ifeq ($(UNAME),SunOS) +LIBS += -lsocket -liconv -lgen +endif + ifneq (,$(filter Linux GNU GNU/%, $(UNAME))) I3_CPPFLAGS += -D_GNU_SOURCE endif diff --git a/i3-config-wizard/main.c b/i3-config-wizard/main.c index 4c1d9697..9b8a486d 100644 --- a/i3-config-wizard/main.c +++ b/i3-config-wizard/main.c @@ -799,7 +799,7 @@ int main(int argc, char *argv[]) { struct stat stbuf; sasprintf(&config_dir, "%s/i3", xdg_config_home); if (stat(config_dir, &stbuf) != 0) - if (!mkdirp(config_dir)) + if (mkdirp(config_dir, DEFAULT_DIR_MODE) != 0) err(EXIT_FAILURE, "mkdirp(%s) failed", config_dir); free(config_dir); free(xdg_config_home); diff --git a/include/libi3.h b/include/libi3.h index 69c44528..971e565e 100644 --- a/include/libi3.h +++ b/include/libi3.h @@ -21,6 +21,8 @@ #include #endif +#define DEFAULT_DIR_MODE (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) + /** * Opaque data structure for storing strings. * @@ -471,8 +473,10 @@ char *resolve_tilde(const char *path); */ char *get_config_path(const char *override_configpath, bool use_system_paths); +#if !defined(__sun) /** * Emulates mkdir -p (creates any missing folders) * */ -bool mkdirp(const char *path); +int mkdirp(const char *path, mode_t mode); +#endif diff --git a/libi3/mkdirp.c b/libi3/mkdirp.c index 95c31b59..c64b80a3 100644 --- a/libi3/mkdirp.c +++ b/libi3/mkdirp.c @@ -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 diff --git a/src/ipc.c b/src/ipc.c index 51a3d223..4af78ab2 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -1087,7 +1087,7 @@ int ipc_create_socket(const char *filename) { char *copy = sstrdup(resolved); const char *dir = dirname(copy); if (!path_exists(dir)) - mkdirp(dir); + mkdirp(dir, DEFAULT_DIR_MODE); free(copy); /* Unlink the unix domain socket before */ diff --git a/src/util.c b/src/util.c index 0a8ba6e2..5568fc71 100644 --- a/src/util.c +++ b/src/util.c @@ -222,7 +222,7 @@ char *store_restart_layout(void) { char *filenamecopy = sstrdup(filename); char *base = dirname(filenamecopy); DLOG("Creating \"%s\" for storing the restart layout\n", base); - if (!mkdirp(base)) + if (mkdirp(base, DEFAULT_DIR_MODE) != 0) ELOG("Could not create \"%s\" for storing the restart layout, layout will be lost.\n", base); free(filenamecopy);