aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--big-brother.c9
-rw-r--r--brightness.c6
-rw-r--r--ddc-ci.c9
-rw-r--r--fancontrol-ng.c27
m---------liberty0
-rw-r--r--priod.c19
-rw-r--r--siprandom.c4
-rw-r--r--wmstatus.c122
8 files changed, 79 insertions, 117 deletions
diff --git a/big-brother.c b/big-brother.c
index c5c9c1a..a3dd0e8 100644
--- a/big-brother.c
+++ b/big-brother.c
@@ -110,15 +110,14 @@ app_context_init (struct app_context *self)
{
memset (self, 0, sizeof *self);
- str_map_init (&self->config);
- self->config.free = free;
+ self->config = str_map_make (free);
simple_config_load_defaults (&self->config, g_config_table);
if (!(self->dpy = XOpenDisplay (NULL)))
exit_fatal ("cannot open display");
poller_init (&self->poller);
- poller_fd_init (&self->x_event, &self->poller,
+ self->x_event = poller_fd_make (&self->poller,
ConnectionNumber (self->dpy));
self->net_active_window =
@@ -372,8 +371,8 @@ main (int argc, char *argv[])
{ 0, NULL, NULL, 0, NULL }
};
- struct opt_handler oh;
- opt_handler_init (&oh, argc, argv, opts, NULL, "Activity tracker.");
+ struct opt_handler oh =
+ opt_handler_make (argc, argv, opts, NULL, "Activity tracker.");
int c;
while ((c = opt_handler_get (&oh)) != -1)
diff --git a/brightness.c b/brightness.c
index 29172f6..62dc1b7 100644
--- a/brightness.c
+++ b/brightness.c
@@ -121,8 +121,7 @@ read_value (int dir, const char *filename, struct error **e)
return -1;
}
- struct str s;
- str_init (&s);
+ struct str s = str_make ();
long value;
if (!read_line (fp, &s)
@@ -163,8 +162,7 @@ set_backlight (int dir, long diff, struct error **e)
"%s: %s: %s", "brightness", "openat", strerror (errno));
}
- struct str s;
- str_init (&s);
+ struct str s = str_make ();
str_append_printf (&s, "%ld", req);
bool result = write (fd, s.str, s.len) == (ssize_t) s.len;
str_free (&s);
diff --git a/ddc-ci.c b/ddc-ci.c
index 0edce8a..a6854b0 100644
--- a/ddc-ci.c
+++ b/ddc-ci.c
@@ -125,8 +125,7 @@ static bool
ddc_send (int fd, unsigned command, void *args, size_t args_len,
struct error **e)
{
- struct str buf;
- str_init (&buf);
+ struct str buf = str_make ();
str_pack_u8 (&buf, DDC_ADDRESS_HOST | I2C_READ);
str_pack_u8 (&buf, DDC_LENGTH_XOR | (args_len + 1));
str_pack_u8 (&buf, command);
@@ -174,8 +173,7 @@ ddc_read (int fd, unsigned *command, void *out_buf, size_t *n_read,
if (ioctl (fd, I2C_RDWR, &data) < 0)
return error_set (e, "%s: %s", "ioctl", strerror (errno));
- struct msg_unpacker unpacker;
- msg_unpacker_init (&unpacker, buf, sizeof buf);
+ struct msg_unpacker unpacker = msg_unpacker_make (buf, sizeof buf);
uint8_t sender, length, cmd;
(void) msg_unpacker_u8 (&unpacker, &sender);
@@ -222,8 +220,7 @@ vcp_get_feature (int fd, uint8_t feature, struct vcp_feature_readout *out,
if (command != DDC_GET_VCP_FEATURE_REPLY || len != 7)
return error_set (e, "invalid response");
- struct msg_unpacker unpacker;
- msg_unpacker_init (&unpacker, buf, len);
+ struct msg_unpacker unpacker = msg_unpacker_make (buf, len);
uint8_t result; msg_unpacker_u8 (&unpacker, &result);
uint8_t vcp_opcode; msg_unpacker_u8 (&unpacker, &vcp_opcode);
diff --git a/fancontrol-ng.c b/fancontrol-ng.c
index f1d9c90..8ae3f47 100644
--- a/fancontrol-ng.c
+++ b/fancontrol-ng.c
@@ -64,8 +64,7 @@ log_message_custom (void *user_data, const char *quote, const char *fmt,
static char *
read_file_cstr (const char *path, struct error **e)
{
- struct str s;
- str_init (&s);
+ struct str s = str_make ();
if (read_file (path, &s, e))
return str_steal (&s);
str_free (&s);
@@ -100,11 +99,9 @@ write_file_printf (const char *path, struct error **e, const char *format, ...)
static bool
write_file_printf (const char *path, struct error **e, const char *format, ...)
{
- struct str s;
- str_init (&s);
-
va_list ap;
va_start (ap, format);
+ struct str s = str_make ();
str_append_vprintf (&s, format, ap);
va_end (ap);
@@ -334,8 +331,8 @@ struct pwm_iter
static void
pwm_iter_init (struct pwm_iter *self, struct device *device)
{
- str_map_iter_init (&self->object_iter,
- &config_item_get (device->config, "pwms", NULL)->value.object);
+ self->object_iter = str_map_iter_make
+ (&config_item_get (device->config, "pwms", NULL)->value.object);
self->device = device;
self->paths = NULL;
}
@@ -407,7 +404,7 @@ device_create (struct app_context *ctx, const char *path,
self->config = root;
self->path = xstrdup (path);
- poller_timer_init (&self->timer, &ctx->poller);
+ self->timer = poller_timer_make (&ctx->poller);
self->timer.dispatcher = (poller_timer_fn) device_run;
self->timer.user_data = self;
@@ -463,9 +460,7 @@ check_device_configuration (struct config_item *subtree, struct error **e)
return error_set (e, "no PWMs defined");
// Check regular fields in all PWM subobjects
- struct str_map_iter iter;
- str_map_iter_init (&iter, &pwms->value.object);
-
+ struct str_map_iter iter = str_map_iter_make (&pwms->value.object);
struct config_item *pwm;
struct error *error = NULL;
while ((pwm = str_map_iter_next (&iter)))
@@ -500,8 +495,8 @@ load_configuration (struct app_context *ctx, const char *config_path)
exit (EXIT_FAILURE);
}
- struct str_map_iter iter;
- str_map_iter_init (&iter, &(ctx->config = root)->value.object);
+ struct str_map_iter iter =
+ str_map_iter_make (&(ctx->config = root)->value.object);
struct config_item *subtree;
while ((subtree = str_map_iter_next (&iter)))
@@ -580,8 +575,8 @@ parse_program_arguments (int argc, char **argv)
{ 0, NULL, NULL, 0, NULL }
};
- struct opt_handler oh;
- opt_handler_init (&oh, argc, argv, opts, "CONFIG", "Fan controller.");
+ struct opt_handler oh =
+ opt_handler_make (argc, argv, opts, "CONFIG", "Fan controller.");
int c;
while ((c = opt_handler_get (&oh)) != -1)
@@ -628,7 +623,7 @@ main (int argc, char *argv[])
setup_signal_handlers ();
struct poller_fd signal_event;
- poller_fd_init (&signal_event, &ctx.poller, g_signal_pipe[0]);
+ signal_event = poller_fd_make (&ctx.poller, g_signal_pipe[0]);
signal_event.dispatcher = (poller_fd_fn) on_signal_pipe_readable;
signal_event.user_data = &ctx;
poller_fd_set (&signal_event, POLLIN);
diff --git a/liberty b/liberty
-Subproject 17322a368656f99ab25766161c717629da5b6ee
+Subproject 6e9217e5d05d95849fbaa795f92eca4ad86b150
diff --git a/priod.c b/priod.c
index dcce2ff..0996ee2 100644
--- a/priod.c
+++ b/priod.c
@@ -132,8 +132,7 @@ load_configuration (struct app_context *ctx, const char *config_path)
exit (EXIT_FAILURE);
}
- struct str_map_iter iter;
- str_map_iter_init (&iter, &root->value.object);
+ struct str_map_iter iter = str_map_iter_make (&root->value.object);
ctx->rules = xcalloc (iter.map->len, sizeof *ctx->rules);
ctx->rules_len = 0;
@@ -286,10 +285,8 @@ on_exec_name (struct app_context *ctx, int pid, const char *program_name)
return;
}
- struct str_map set;
- str_map_init (&set);
-
// This has an inherent race condition, but let's give it a try
+ struct str_map set = str_map_make (NULL);
for (size_t retries = 3; retries--; )
if (reprioritize (pid, program_name, dir, rule, &set))
break;
@@ -303,8 +300,7 @@ on_exec (struct app_context *ctx, int pid)
{
// This is inherently racy but there seems to be no better way to do it
char *path = xstrdup_printf ("/proc/%d/cmdline", pid);
- struct str cmdline;
- str_init (&cmdline);
+ struct str cmdline = str_make ();
struct error *e = NULL;
if (read_file (path, &cmdline, &e))
@@ -408,8 +404,7 @@ parse_program_arguments (int argc, char **argv)
{ 0, NULL, NULL, 0, NULL }
};
- struct opt_handler oh;
- opt_handler_init (&oh, argc, argv, opts, "CONFIG",
+ struct opt_handler oh = opt_handler_make (argc, argv, opts, "CONFIG",
"Process reprioritizing daemon.");
int c;
@@ -498,8 +493,8 @@ main (int argc, char *argv[])
setup_signal_handlers ();
- struct poller_fd signal_event;
- poller_fd_init (&signal_event, &ctx.poller, g_signal_pipe[0]);
+ struct poller_fd signal_event =
+ poller_fd_make (&ctx.poller, g_signal_pipe[0]);
signal_event.dispatcher = (poller_fd_fn) on_signal_pipe_readable;
signal_event.user_data = &ctx;
poller_fd_set (&signal_event, POLLIN);
@@ -538,7 +533,7 @@ main (int argc, char *argv[])
if (write (ctx.proc_fd, &subscription, sizeof subscription) < 0)
exit_fatal ("failed to subscribe for events: %s", strerror (errno));
- poller_fd_init (&ctx.proc_event, &ctx.poller, ctx.proc_fd);
+ ctx.proc_event = poller_fd_make (&ctx.poller, ctx.proc_fd);
ctx.proc_event.dispatcher = (poller_fd_fn) on_event;
ctx.proc_event.user_data = &ctx;
poller_fd_set (&ctx.proc_event, POLLIN);
diff --git a/siprandom.c b/siprandom.c
index 28074de..690772c 100644
--- a/siprandom.c
+++ b/siprandom.c
@@ -33,8 +33,8 @@ parse_program_arguments (int argc, char **argv)
{ 0, NULL, NULL, 0, NULL }
};
- struct opt_handler oh;
- opt_handler_init (&oh, argc, argv, opts, "CONFIG", "PRNG.");
+ struct opt_handler oh =
+ opt_handler_make (argc, argv, opts, "CONFIG", "PRNG.");
int c;
while ((c = opt_handler_get (&oh)) != -1)
diff --git a/wmstatus.c b/wmstatus.c
index c500d7a..9d9e3e9 100644
--- a/wmstatus.c
+++ b/wmstatus.c
@@ -180,10 +180,9 @@ poller_pa_io_new (pa_mainloop_api *api, int fd_, pa_io_event_flags_t events,
self->user_data = userdata;
struct poller_pa *data = api->userdata;
- struct poller_fd *fd = &self->fd;
- poller_fd_init (fd, data->poller, fd_);
- fd->user_data = self;
- fd->dispatcher = poller_pa_io_dispatcher;
+ self->fd = poller_fd_make (data->poller, fd_);
+ self->fd.user_data = self;
+ self->fd.dispatcher = poller_pa_io_dispatcher;
// FIXME: under x2go PA tries to register twice for the same FD,
// which fails with our curent poller implementation;
@@ -249,10 +248,9 @@ poller_pa_time_new (pa_mainloop_api *api, const struct timeval *tv,
self->user_data = userdata;
struct poller_pa *data = api->userdata;
- struct poller_timer *timer = &self->timer;
- poller_timer_init (timer, data->poller);
- timer->user_data = self;
- timer->dispatcher = poller_pa_time_dispatcher;
+ self->timer = poller_timer_make (data->poller);
+ self->timer.user_data = self;
+ self->timer.dispatcher = poller_pa_time_dispatcher;
poller_pa_time_restart (self, tv);
LIST_PREPEND (data->time_list, self);
@@ -296,12 +294,11 @@ poller_pa_defer_new (pa_mainloop_api *api,
self->user_data = userdata;
struct poller_pa *data = api->userdata;
- struct poller_idle *idle = &self->idle;
- poller_idle_init (idle, data->poller);
- idle->user_data = self;
- idle->dispatcher = poller_pa_defer_dispatcher;
+ self->idle = poller_idle_make (data->poller);
+ self->idle.user_data = self;
+ self->idle.dispatcher = poller_pa_defer_dispatcher;
- poller_idle_set (idle);
+ poller_idle_set (&self->idle);
LIST_PREPEND (data->defer_list, self);
return self;
}
@@ -441,8 +438,8 @@ static void
nut_parser_init (struct nut_parser *self)
{
self->state = NUT_STATE_START_LINE;
- str_init (&self->current_field);
- strv_init (&self->fields);
+ self->current_field = str_make ();
+ self->fields = strv_make ();
}
static void
@@ -621,12 +618,12 @@ nut_client_init (struct nut_client *self, struct poller *poller)
self->poller = poller;
self->socket = -1;
- str_init (&self->read_buffer);
- str_init (&self->write_buffer);
+ self->read_buffer = str_make ();
+ self->write_buffer = str_make ();
nut_parser_init (&self->parser);
- poller_fd_init (&self->socket_event, poller, -1);
+ self->socket_event = poller_fd_make (poller, -1);
}
static void
@@ -751,8 +748,7 @@ nut_client_dispatch (struct nut_client *self, struct nut_response *response)
static bool
nut_client_parse_line (struct nut_client *self)
{
- struct str reconstructed;
- str_init (&reconstructed);
+ struct str reconstructed = str_make ();
nut_client_serialize (self->parser.fields.vector, &reconstructed);
print_debug ("NUT >> %s", reconstructed.str);
str_free (&reconstructed);
@@ -772,7 +768,7 @@ nut_client_parse_line (struct nut_client *self)
else
{
struct nut_line *line = xcalloc (1, sizeof *line);
- strv_init (&line->fields);
+ line->fields = strv_make ();
strv_append_vector (&line->fields, fields->vector);
LIST_APPEND_WITH_TAIL (self->data, self->data_tail, line);
}
@@ -861,8 +857,7 @@ static void nut_client_send_command
static void
nut_client_send_commandv (struct nut_client *self, char **commands)
{
- struct str line;
- str_init (&line);
+ struct str line = str_make ();
nut_client_serialize (commands, &line);
print_debug ("NUT << %s", line.str);
@@ -876,8 +871,7 @@ nut_client_send_commandv (struct nut_client *self, char **commands)
static void
nut_client_send_command (struct nut_client *self, const char *command, ...)
{
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
va_list ap;
va_start (ap, command);
@@ -898,7 +892,7 @@ nut_client_finish_connection (struct nut_client *self, int socket)
self->socket = socket;
self->state = NUT_CONNECTED;
- poller_fd_init (&self->socket_event, self->poller, self->socket);
+ self->socket_event = poller_fd_make (self->poller, self->socket);
self->socket_event.dispatcher = nut_client_on_ready;
self->socket_event.user_data = self;
@@ -1026,7 +1020,7 @@ backend_dwm_new (Display *dpy)
self->super.flush = backend_dwm_flush;
self->dpy = dpy;
- strv_init (&self->items);
+ self->items = strv_make ();
return &self->super;
}
@@ -1116,7 +1110,7 @@ backend_i3_new (void)
self->super.add = backend_i3_add;
self->super.flush = backend_i3_flush;
- strv_init (&self->items);
+ self->items = strv_make ();
return &self->super;
}
@@ -1253,8 +1247,7 @@ app_context_init (struct app_context *self)
{
memset (self, 0, sizeof *self);
- str_map_init (&self->config);
- self->config.free = free;
+ self->config = str_map_make (free);
simple_config_load_defaults (&self->config, g_config_table);
if (!(self->dpy = XkbOpenDisplay
@@ -1264,15 +1257,15 @@ app_context_init (struct app_context *self)
poller_init (&self->poller);
self->api = poller_pa_new (&self->poller);
- strv_init (&self->command_current);
+ self->command_current = strv_make ();
self->command_pid = -1;
self->command_fd = -1;
- poller_fd_init (&self->command_event, &self->poller, -1);
- str_init (&self->command_buffer);
+ self->command_event = poller_fd_make (&self->poller, -1);
+ self->command_buffer = str_make ();
set_cloexec (ConnectionNumber (self->dpy));
- poller_fd_init (&self->x_event, &self->poller,
- ConnectionNumber (self->dpy));
+ self->x_event =
+ poller_fd_make (&self->poller, ConnectionNumber (self->dpy));
app_context_init_xsync (self);
@@ -1286,13 +1279,12 @@ app_context_init (struct app_context *self)
dbus_error_free (&err);
}
- mpd_client_init (&self->mpd_client, &self->poller);
+ self->mpd_client = mpd_client_make (&self->poller);
nut_client_init (&self->nut_client, &self->poller);
- str_map_init (&self->nut_ups_info);
- self->nut_ups_info.free = str_map_destroy;
+ self->nut_ups_info = str_map_make (str_map_destroy);
- strv_init (&self->sink_ports);
+ self->sink_ports = strv_make ();
}
static void
@@ -1355,8 +1347,7 @@ read_value (int dir, const char *filename, struct error **e)
return NULL;
}
- struct str s;
- str_init (&s);
+ struct str s = str_make ();
bool success = read_line (fp, &s);
fclose (fp);
@@ -1400,8 +1391,7 @@ read_battery_status (int dir, struct error **e)
error_propagate (e, error);
else
{
- struct str s;
- str_init (&s);
+ struct str s = str_make ();
str_append (&s, status);
// Dell is being unreasonable and seems to set charge_now
@@ -1509,8 +1499,7 @@ make_volume_status (struct app_context *ctx)
if (!ctx->sink_volume.channels)
return xstrdup ("");
- struct str s;
- str_init (&s);
+ struct str s = str_make ();
if (ctx->sink_muted)
str_append (&s, "Muted ");
@@ -1750,7 +1739,7 @@ on_command_start (void *user_data)
ctx->command_pid = pid;
str_reset (&ctx->command_buffer);
- poller_fd_init (&ctx->command_event, &ctx->poller,
+ ctx->command_event = poller_fd_make (&ctx->poller,
(ctx->command_fd = output_pipe[PIPE_READ]));
ctx->command_event.dispatcher = on_command_ready;
ctx->command_event.user_data = ctx;
@@ -1763,9 +1752,8 @@ on_command_start (void *user_data)
static void
mpd_vector_to_map (const struct strv *data, struct str_map *map)
{
- str_map_init (map);
+ *map = str_map_make (free);
map->key_xfrm = tolower_ascii_strxfrm;
- map->free = free;
char *key, *value;
for (size_t i = 0; i < data->len; i++)
@@ -1795,8 +1783,7 @@ mpd_on_info_response (const struct mpd_response *response,
free (ctx->mpd_status);
ctx->mpd_status = NULL;
- struct str s;
- str_init (&s);
+ struct str s = str_make ();
const char *value;
if ((value = str_map_find (&map, "state")))
@@ -1996,13 +1983,10 @@ nut_process_ups (struct app_context *ctx, struct strv *ups_list,
if (!soft_assert (xstrtoul (&runtime_sec, runtime, 10)))
return;
- struct strv items;
- strv_init (&items);
-
+ struct strv items = strv_make ();
bool running_on_batteries = false;
- struct strv v;
- strv_init (&v);
+ struct strv v = strv_make ();
cstr_split (status, " ", true, &v);
for (size_t i = 0; i < v.len; i++)
{
@@ -2027,8 +2011,7 @@ nut_process_ups (struct app_context *ctx, struct strv *ups_list,
&& xstrtoul (&threshold_n, threshold, 10)
&& load_n >= threshold_n)
{
- struct str item;
- str_init (&item);
+ struct str item = str_make ();
str_append_printf (&item, "load %s%%", load);
const char *power = str_map_find (dict, "ups.realpower.nominal");
@@ -2043,10 +2026,8 @@ nut_process_ups (struct app_context *ctx, struct strv *ups_list,
strv_append_owned (&items, str_steal (&item));
}
- struct str result;
- str_init (&result);
+ struct str result = str_make ();
str_append (&result, "UPS: ");
-
for (size_t i = 0; i < items.len; i++)
{
if (i) str_append (&result, "; ");
@@ -2063,11 +2044,9 @@ nut_on_logout_response (const struct nut_response *response, void *user_data)
return;
struct app_context *ctx = user_data;
- struct strv ups_list;
- strv_init (&ups_list);
+ struct strv ups_list = strv_make ();
- struct str_map_iter iter;
- str_map_iter_init (&iter, &ctx->nut_ups_info);
+ struct str_map_iter iter = str_map_iter_make (&ctx->nut_ups_info);
struct str_map *dict;
while ((dict = str_map_iter_next (&iter)))
nut_process_ups (ctx, &ups_list, iter.link->key, dict);
@@ -2077,8 +2056,7 @@ nut_on_logout_response (const struct nut_response *response, void *user_data)
if (ups_list.len)
{
- struct str status;
- str_init (&status);
+ struct str status = str_make ();
str_append (&status, ups_list.vector[0]);
for (size_t i = 1; i < ups_list.len; i++)
str_append_printf (&status, " %s", ups_list.vector[0]);
@@ -2097,8 +2075,8 @@ nut_store_var (struct app_context *ctx,
struct str_map *map;
if (!(map = str_map_find (&ctx->nut_ups_info, ups_name)))
{
- str_map_init ((map = xcalloc (1, sizeof *map)));
- map->free = free;
+ map = xmalloc (sizeof *map);
+ *map = str_map_make (free);
str_map_set (&ctx->nut_ups_info, ups_name, map);
}
@@ -2777,7 +2755,7 @@ setup_signal_handlers (struct app_context *ctx)
if (sigaction (SIGCHLD, &sa, NULL) == -1)
print_error ("%s: %s", "sigaction", strerror (errno));
- poller_fd_init (&g_signal_event, &ctx->poller, g_signal_pipe[PIPE_READ]);
+ g_signal_event = poller_fd_make (&ctx->poller, g_signal_pipe[PIPE_READ]);
g_signal_event.dispatcher = (poller_fd_fn) on_signal_pipe_readable;
g_signal_event.user_data = ctx;
poller_fd_set (&g_signal_event, POLLIN);
@@ -2787,7 +2765,7 @@ static void
poller_timer_init_and_set (struct poller_timer *self, struct poller *poller,
poller_timer_fn cb, void *user_data)
{
- poller_timer_init (self, poller);
+ *self = poller_timer_make (poller);
self->dispatcher = cb;
self->user_data = user_data;
@@ -2811,8 +2789,8 @@ main (int argc, char *argv[])
{ 0, NULL, NULL, 0, NULL }
};
- struct opt_handler oh;
- opt_handler_init (&oh, argc, argv, opts, NULL, "Set root window name.");
+ struct opt_handler oh =
+ opt_handler_make (argc, argv, opts, NULL, "Set root window name.");
bool i3bar = false;
int c;