#include "xcb.h"
#include "ucs2_to_utf8.h"
#include "config.h"
+#include "libi3.h"
#endif
int n = 0;
int rec = 0;
int buffer_len = STDIN_CHUNK_SIZE;
- char *buffer = malloc(buffer_len);
+ char *buffer = smalloc(buffer_len);
buffer[0] = '\0';
while(1) {
n = read(fd, buffer + rec, buffer_len - rec);
if (rec == buffer_len) {
buffer_len += STDIN_CHUNK_SIZE;
- buffer = realloc(buffer, buffer_len);
+ buffer = srealloc(buffer, buffer_len);
}
}
if (*buffer == '\0') {
/* We set O_NONBLOCK because blocking is evil in event-driven software */
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);
- stdin_io = malloc(sizeof(ev_io));
+ stdin_io = smalloc(sizeof(ev_io));
ev_io_init(stdin_io, &stdin_io_cb, STDIN_FILENO, EV_READ);
ev_io_start(main_loop, stdin_io);
/* We must cleanup, if the child unexpectedly terminates */
- child_sig = malloc(sizeof(ev_child));
+ child_sig = smalloc(sizeof(ev_child));
ev_child_init(child_sig, &child_sig_cb, child_pid, 0);
ev_child_start(main_loop, child_sig);
#endif
FREE(cur_key);
- cur_key = malloc(sizeof(unsigned char) * (keyLen + 1));
+ cur_key = smalloc(sizeof(unsigned char) * (keyLen + 1));
strncpy(cur_key, (const char*) keyVal, keyLen);
cur_key[keyLen] = '\0';
/* First we only read the header, because we know its length */
uint32_t header_len = strlen(I3_IPC_MAGIC) + sizeof(uint32_t)*2;
- char *header = malloc(header_len);
- if (header == NULL) {
- ELOG("Could not allocate memory: %s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
+ char *header = smalloc(header_len);
/* We first parse the fixed-length IPC-header, to know, how much data
* we have to expect */
/* Now that we know, what to expect, we can start read()ing the rest
* of the message */
- char *buffer = malloc(size + 1);
- if (buffer == NULL) {
- /* EOF received. Since i3 will restart i3bar instances as appropriate,
- * we exit here. */
- DLOG("EOF received, exiting...\n");
- exit(EXIT_SUCCESS);
- }
+ char *buffer = smalloc(size + 1);
rec = 0;
while (rec < size) {
/* TODO: I'm not entirely sure if this buffer really has to contain more
* than the pure header (why not just write() the payload from *payload?),
* but we leave it for now */
- char *buffer = malloc(to_write);
- if (buffer == NULL) {
- ELOG("Could not allocate memory: %s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
-
+ char *buffer = smalloc(to_write);
char *walk = buffer;
strncpy(buffer, I3_IPC_MAGIC, strlen(I3_IPC_MAGIC));
exit(EXIT_FAILURE);
}
- i3_connection = malloc(sizeof(ev_io));
- if (i3_connection == NULL) {
- ELOG("malloc() failed: %s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
+ i3_connection = smalloc(sizeof(ev_io));
ev_io_init(i3_connection, &got_data, sockfd, EV_READ);
ev_io_start(main_loop, i3_connection);
return 1;
#include <glob.h>
#include "common.h"
-#include "libi3.h"
/*
* Glob path, i.e. expand ~
ELOG("glob() failed\n");
exit(EXIT_FAILURE);
}
- char *result = strdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : path);
- if (result == NULL) {
- ELOG("malloc() failed: %s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
+ char *result = sstrdup(globbuf.gl_pathc > 0 ? globbuf.gl_pathv[0] : path);
globfree(&globbuf);
return result;
}
/* We listen to SIGTERM/QUIT/INT and try to exit cleanly, by stopping the main-loop.
* We only need those watchers on the stack, so putting them on the stack saves us
* some calls to free() */
- ev_signal *sig_term = malloc(sizeof(ev_signal));
- ev_signal *sig_int = malloc(sizeof(ev_signal));
- ev_signal *sig_hup = malloc(sizeof(ev_signal));
-
- if (sig_term == NULL || sig_int == NULL || sig_hup == NULL) {
- ELOG("malloc() failed: %s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
+ ev_signal *sig_term = smalloc(sizeof(ev_signal));
+ ev_signal *sig_int = smalloc(sizeof(ev_signal));
+ ev_signal *sig_hup = smalloc(sizeof(ev_signal));
ev_signal_init(sig_term, &sig_cb, SIGTERM);
ev_signal_init(sig_int, &sig_cb, SIGINT);
struct outputs_json_params *params = (struct outputs_json_params*) params_;
if (!strcmp(params->cur_key, "current_workspace")) {
- char *copy = malloc(sizeof(const unsigned char) * (len + 1));
+ char *copy = smalloc(sizeof(const unsigned char) * (len + 1));
strncpy(copy, (const char*) val, len);
copy[len] = '\0';
return 0;
}
- char *name = malloc(sizeof(const unsigned char) * (len + 1));
+ char *name = smalloc(sizeof(const unsigned char) * (len + 1));
strncpy(name, (const char*) val, len);
name[len] = '\0';
i3_output *new_output = NULL;
if (params->cur_key == NULL) {
- new_output = malloc(sizeof(i3_output));
+ new_output = smalloc(sizeof(i3_output));
new_output->name = NULL;
new_output->ws = 0,
memset(&new_output->rect, 0, sizeof(rect));
new_output->bar = XCB_NONE;
- new_output->workspaces = malloc(sizeof(struct ws_head));
+ new_output->workspaces = smalloc(sizeof(struct ws_head));
TAILQ_INIT(new_output->workspaces);
- new_output->trayclients = malloc(sizeof(struct tc_head));
+ new_output->trayclients = smalloc(sizeof(struct tc_head));
TAILQ_INIT(new_output->trayclients);
params->outputs_walk = new_output;
struct outputs_json_params *params = (struct outputs_json_params*) params_;
FREE(params->cur_key);
- params->cur_key = malloc(sizeof(unsigned char) * (keyLen + 1));
+ params->cur_key = smalloc(sizeof(unsigned char) * (keyLen + 1));
strncpy(params->cur_key, (const char*) keyVal, keyLen);
params->cur_key[keyLen] = '\0';
*
*/
void init_outputs() {
- outputs = malloc(sizeof(struct outputs_head));
+ outputs = smalloc(sizeof(struct outputs_head));
SLIST_INIT(outputs);
}
#include <err.h>
#include <iconv.h>
+#include "libi3.h"
+
static iconv_t conversion_descriptor = 0;
static iconv_t conversion_descriptor2 = 0;
/* UTF-8 may consume up to 4 byte */
int buffer_size = 8;
- char *buffer = calloc(buffer_size, 1);
- if (buffer == NULL)
- err(EXIT_FAILURE, "malloc() failed\n");
+ char *buffer = scalloc(buffer_size);
size_t output_size = buffer_size;
/* We need to use an additional pointer, because iconv() modifies it */
char *output = buffer;
/* UCS-2 consumes exactly two bytes for each glyph */
int buffer_size = input_size * 2;
- char *buffer = malloc(buffer_size);
- if (buffer == NULL)
- err(EXIT_FAILURE, "malloc() failed\n");
+ char *buffer = smalloc(buffer_size);
size_t output_size = buffer_size;
/* We need to use an additional pointer, because iconv() modifies it */
char *output = buffer;
if (!strcmp(params->cur_key, "name")) {
/* Save the name */
- params->workspaces_walk->name = malloc(sizeof(const unsigned char) * (len + 1));
+ params->workspaces_walk->name = smalloc(sizeof(const unsigned char) * (len + 1));
strncpy(params->workspaces_walk->name, (const char*) val, len);
params->workspaces_walk->name[len] = '\0';
if (!strcmp(params->cur_key, "output")) {
/* We add the ws to the TAILQ of the output, it belongs to */
- output_name = malloc(sizeof(const unsigned char) * (len + 1));
+ output_name = smalloc(sizeof(const unsigned char) * (len + 1));
strncpy(output_name, (const char*) val, len);
output_name[len] = '\0';
params->workspaces_walk->output = get_output_by_name(output_name);
i3_ws *new_workspace = NULL;
if (params->cur_key == NULL) {
- new_workspace = malloc(sizeof(i3_ws));
+ new_workspace = smalloc(sizeof(i3_ws));
new_workspace->num = -1;
new_workspace->name = NULL;
new_workspace->visible = 0;
struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
FREE(params->cur_key);
- params->cur_key = malloc(sizeof(unsigned char) * (keyLen + 1));
- if (params->cur_key == NULL) {
- ELOG("Could not allocate memory: %s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
+ params->cur_key = smalloc(sizeof(unsigned char) * (keyLen + 1));
strncpy(params->cur_key, (const char*) keyVal, keyLen);
params->cur_key[keyLen] = '\0';
for (len = 0; len < n && str[len]; len++)
continue;
- if ((copy = malloc(len + 1)) == NULL)
- return (NULL);
+ copy = smalloc(len + 1);
memcpy(copy, str, len);
copy[len] = '\0';
return (copy);
values);
/* send the XEMBED_EMBEDDED_NOTIFY message */
- void *event = calloc(32, 1);
+ void *event = scalloc(32);
xcb_client_message_event_t *ev = event;
ev->response_type = XCB_CLIENT_MESSAGE;
ev->window = client;
} else {
DLOG("Not mapping dock client yet\n");
}
- trayclient *tc = malloc(sizeof(trayclient));
+ trayclient *tc = smalloc(sizeof(trayclient));
tc->win = client;
tc->mapped = map_it;
tc->xe_version = xe_version;
/* The various Watchers to communicate with xcb */
- xcb_io = malloc(sizeof(ev_io));
- xcb_prep = malloc(sizeof(ev_prepare));
- xcb_chk = malloc(sizeof(ev_check));
+ xcb_io = smalloc(sizeof(ev_io));
+ xcb_prep = smalloc(sizeof(ev_prepare));
+ xcb_chk = smalloc(sizeof(ev_check));
ev_io_init(xcb_io, &xcb_io_cb, xcb_get_file_descriptor(xcb_connection), EV_READ);
ev_prepare_init(xcb_prep, &xcb_prep_cb);
exit(EXIT_FAILURE);
}
- xkb_io = malloc(sizeof(ev_io));
+ xkb_io = smalloc(sizeof(ev_io));
ev_io_init(xkb_io, &xkb_io_cb, ConnectionNumber(xkb_dpy), EV_READ);
ev_io_start(main_loop, xkb_io);
XFlush(xkb_dpy);
}
/* Inform clients waiting for a new _NET_SYSTEM_TRAY that we are here */
- void *event = calloc(32, 1);
+ void *event = scalloc(32);
xcb_client_message_event_t *ev = event;
ev->response_type = XCB_CLIENT_MESSAGE;
ev->window = xcb_root;