common: Add znew/znew_n() macros

This commit is contained in:
John Lindgren 2022-09-18 15:22:26 -04:00
parent da57483961
commit a54d378e6c
26 changed files with 47 additions and 47 deletions

View file

@ -28,7 +28,7 @@ parse_modifier(const char *symname)
struct keybind *
keybind_create(const char *keybind)
{
struct keybind *k = xzalloc(sizeof(struct keybind));
struct keybind *k = znew(*k);
xkb_keysym_t keysyms[MAX_KEYSYMS];
gchar **symnames = g_strsplit(keybind, "-", -1);
for (int i = 0; symnames[i]; i++) {

View file

@ -38,7 +38,7 @@ get_device_type(const char *s)
struct libinput_category *
libinput_category_create(void)
{
struct libinput_category *l = xzalloc(sizeof(struct libinput_category));
struct libinput_category *l = znew(*l);
libinput_category_init(l);
wl_list_insert(&rc.libinput_categories, &l->link);
return l;

View file

@ -109,7 +109,7 @@ mousebind_create(const char *context)
wlr_log(WLR_ERROR, "mousebind context not specified");
return NULL;
}
struct mousebind *m = xzalloc(sizeof(struct mousebind));
struct mousebind *m = znew(*m);
m->context = context_from_str(context);
if (m->context != LAB_SSD_NONE) {
wl_list_insert(rc.mousebinds.prev, &m->link);

View file

@ -401,7 +401,7 @@ entry(xmlNode *node, char *nodename, char *content)
} else if (!strcasecmp(nodename, "cycleViewOutlines.core")) {
rc.cycle_preview_outlines = get_bool(content);
} else if (!strcasecmp(nodename, "name.names.desktops")) {
struct workspace *workspace = xzalloc(sizeof(struct workspace));
struct workspace *workspace = znew(*workspace);
workspace->name = xstrdup(content);
wl_list_insert(rc.workspace_config.workspaces.prev, &workspace->link);
} else if (!strcasecmp(nodename, "popupTime.desktops")) {
@ -685,7 +685,7 @@ post_processing(void)
l->type = DEFAULT_DEVICE;
}
if (!wl_list_length(&rc.workspace_config.workspaces)) {
struct workspace *workspace = xzalloc(sizeof(struct workspace));
struct workspace *workspace = znew(*workspace);
workspace->name = xstrdup("Default");
wl_list_insert(rc.workspace_config.workspaces.prev, &workspace->link);
}

View file

@ -79,7 +79,7 @@ build_path(const char *dir, const char *filename)
return NULL;
}
int len = strlen(dir) + strlen(filename) + 2;
char *buffer = xzalloc(len);
char *buffer = znew_n(char, len);
strcat(buffer, dir);
strcat(buffer, "/");
strcat(buffer, filename);
@ -101,13 +101,13 @@ update_activation_env(const char *env_keys)
const char *dbus = "dbus-update-activation-environment ";
const char *systemd = "systemctl --user import-environment ";
cmd = xzalloc(strlen(dbus) + strlen(env_keys) + 1);
cmd = znew_n(char, strlen(dbus) + strlen(env_keys) + 1);
strcat(cmd, dbus);
strcat(cmd, env_keys);
spawn_async_no_shell(cmd);
free(cmd);
cmd = xzalloc(strlen(systemd) + strlen(env_keys) + 1);
cmd = znew_n(char, strlen(systemd) + strlen(env_keys) + 1);
strcat(cmd, systemd);
strcat(cmd, env_keys);
spawn_async_no_shell(cmd);
@ -148,7 +148,7 @@ session_autostart_init(const char *dir)
}
wlr_log(WLR_INFO, "run autostart file %s", autostart);
int len = strlen(autostart) + 4;
char *cmd = xzalloc(len);
char *cmd = znew_n(char, len);
strcat(cmd, "sh ");
strcat(cmd, autostart);
spawn_async_no_shell(cmd);