LIBS += -lrt
endif
+ifeq ($(UNAME),SunOS)
+LIBS += -lsocket -liconv -lgen
+endif
+
ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
I3_CPPFLAGS += -D_GNU_SOURCE
endif
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);
#include <pango/pango.h>
#endif
+#define DEFAULT_DIR_MODE (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
+
/**
* Opaque data structure for storing strings.
*
*/
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
* 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 */
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
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 */
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);