}
}
if (walk != beginning) {
- char *str = scalloc(walk - beginning + 1);
+ char *str = scalloc(walk - beginning + 1, 1);
/* We copy manually to handle escaping of characters. */
int inpos, outpos;
for (inpos = 0, outpos = 0;
switch (o) {
case 's':
FREE(socket_path);
- socket_path = strdup(optarg);
+ socket_path = sstrdup(optarg);
break;
case 'v':
printf("i3-config-wizard " I3_VERSION "\n");
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.
*
* there is no more memory available)
*
*/
-void *scalloc(size_t size);
+void *scalloc(size_t num, size_t size);
/**
* Safe-wrapper around realloc which exits if realloc returns NULL (meaning
*/
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
IPC_HANDLER(command) {
/* To get a properly terminated buffer, we copy
* message_size bytes out of the buffer */
- char *command = scalloc(message_size + 1);
+ char *command = scalloc(message_size + 1, 1);
strncpy(command, (const char *)message, message_size);
LOG("IPC: received: *%s*\n", command);
yajl_gen gen = yajl_gen_alloc(NULL);
/* To get a properly terminated buffer, we copy
* message_size bytes out of the buffer */
- char *bar_id = scalloc(message_size + 1);
+ char *bar_id = scalloc(message_size + 1, 1);
strncpy(bar_id, (const char *)message, message_size);
LOG("IPC: looking for config for bar ID \"%s\"\n", bar_id);
Barconfig *current, *config = NULL;
int event = client->num_events;
client->num_events++;
- client->events = realloc(client->events, client->num_events * sizeof(char *));
+ client->events = srealloc(client->events, client->num_events * sizeof(char *));
/* We copy the string because it is not null-terminated and strndup()
* is missing on some BSD systems */
- client->events[event] = scalloc(len + 1);
+ client->events[event] = scalloc(len + 1, 1);
memcpy(client->events[event], s, len);
DLOG("client is now subscribed to:\n");
set_nonblock(client);
- struct ev_io *package = scalloc(sizeof(struct ev_io));
+ struct ev_io *package = scalloc(1, sizeof(struct ev_io));
ev_io_init(package, ipc_receive_message, client, EV_READ);
ev_io_start(EV_A_ package);
DLOG("IPC: new client connected on fd %d\n", w->fd);
- ipc_client *new = scalloc(sizeof(ipc_client));
+ ipc_client *new = scalloc(1, sizeof(ipc_client));
new->fd = client;
TAILQ_INSERT_TAIL(&all_clients, new, clients);
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 */
/* if the script is not in path, maybe the user installed to a strange
* location and runs the i3 binary with an absolute path. We use
* argv[0]’s dirname */
- char *pathbuf = strdup(start_argv[0]);
+ char *pathbuf = sstrdup(start_argv[0]);
char *dir = dirname(pathbuf);
sasprintf(&migratepath, "%s/%s", dir, name);
argv[0] = migratepath;
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);
int num_args;
for (num_args = 0; start_argv[num_args] != NULL; num_args++)
;
- char **new_argv = scalloc((num_args + 3) * sizeof(char *));
+ char **new_argv = scalloc(num_args + 3, sizeof(char *));
/* copy the arguments, but skip the ones we'll replace */
int write_index = 0;