asprintf wrapper
This commit is contained in:
parent
aa514c94eb
commit
83c523cf53
16
dunst.c
16
dunst.c
@ -506,7 +506,7 @@ void add_notification_to_line_cache(notification *n, int max_width)
|
|||||||
|
|
||||||
/* print dup_count */
|
/* print dup_count */
|
||||||
if (n->dup_count > 0) {
|
if (n->dup_count > 0) {
|
||||||
asprintf(&buf, "(%d)", n->dup_count);
|
sasprintf(&buf, "(%d)", n->dup_count);
|
||||||
} else {
|
} else {
|
||||||
buf = strdup("");
|
buf = strdup("");
|
||||||
}
|
}
|
||||||
@ -514,7 +514,7 @@ void add_notification_to_line_cache(notification *n, int max_width)
|
|||||||
/* print msg */
|
/* print msg */
|
||||||
{
|
{
|
||||||
char *new_buf;
|
char *new_buf;
|
||||||
asprintf(&new_buf, "%s %s", buf, msg);
|
sasprintf(&new_buf, "%s %s", buf, msg);
|
||||||
free(buf);
|
free(buf);
|
||||||
buf = new_buf;
|
buf = new_buf;
|
||||||
}
|
}
|
||||||
@ -530,13 +530,13 @@ void add_notification_to_line_cache(notification *n, int max_width)
|
|||||||
|
|
||||||
char *new_buf;
|
char *new_buf;
|
||||||
if (hours > 0) {
|
if (hours > 0) {
|
||||||
asprintf(&new_buf, "%s (%dh %dm %ds old)", buf, hours,
|
sasprintf(&new_buf, "%s (%dh %dm %ds old)", buf, hours,
|
||||||
minutes, seconds);
|
minutes, seconds);
|
||||||
} else if (minutes > 0) {
|
} else if (minutes > 0) {
|
||||||
asprintf(&new_buf, "%s (%dm %ds old)", buf, minutes,
|
sasprintf(&new_buf, "%s (%dm %ds old)", buf, minutes,
|
||||||
seconds);
|
seconds);
|
||||||
} else {
|
} else {
|
||||||
asprintf(&new_buf, "%s (%ds old)", buf, seconds);
|
sasprintf(&new_buf, "%s (%ds old)", buf, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
@ -694,7 +694,7 @@ void fill_line_cache(int width)
|
|||||||
if (indicate_hidden && queue_cnt > 0) {
|
if (indicate_hidden && queue_cnt > 0) {
|
||||||
if (geometry.h != 1) {
|
if (geometry.h != 1) {
|
||||||
char *tmp;
|
char *tmp;
|
||||||
asprintf(&tmp, "(%d more)", queue_cnt);
|
sasprintf(&tmp, "(%d more)", queue_cnt);
|
||||||
ColorSet *last_colors =
|
ColorSet *last_colors =
|
||||||
line_cache.lines[line_cache.count-1].colors;
|
line_cache.lines[line_cache.count-1].colors;
|
||||||
r_line_cache_append(&line_cache, tmp, last_colors, false);
|
r_line_cache_append(&line_cache, tmp, last_colors, false);
|
||||||
@ -702,7 +702,7 @@ void fill_line_cache(int width)
|
|||||||
} else {
|
} else {
|
||||||
char *old = line_cache.lines[0].str;
|
char *old = line_cache.lines[0].str;
|
||||||
char *new;
|
char *new;
|
||||||
asprintf(&new, "%s (%d more)", old, queue_cnt);
|
sasprintf(&new, "%s (%d more)", old, queue_cnt);
|
||||||
free(old);
|
free(old);
|
||||||
line_cache.lines[0].str = new;
|
line_cache.lines[0].str = new;
|
||||||
}
|
}
|
||||||
@ -1045,7 +1045,7 @@ int init_notification(notification * n, int id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *tmp;
|
char *tmp;
|
||||||
asprintf(&tmp, "%s %s", n->summary, n->body);
|
sasprintf(&tmp, "%s %s", n->summary, n->body);
|
||||||
|
|
||||||
n->urls = extract_urls(tmp);
|
n->urls = extract_urls(tmp);
|
||||||
|
|
||||||
|
@ -438,18 +438,18 @@ void cmdline_usage_append(char *key, char *type, char *description)
|
|||||||
{
|
{
|
||||||
char *key_type;
|
char *key_type;
|
||||||
if (type && strlen(type) > 0)
|
if (type && strlen(type) > 0)
|
||||||
asprintf(&key_type, "%s (%s)", key, type);
|
sasprintf(&key_type, "%s (%s)", key, type);
|
||||||
else
|
else
|
||||||
asprintf(&key_type, "%s", key);
|
sasprintf(&key_type, "%s", key);
|
||||||
|
|
||||||
if (!usage_str) {
|
if (!usage_str) {
|
||||||
asprintf(&usage_str, "%-40s - %s\n", key_type, description);
|
sasprintf(&usage_str, "%-40s - %s\n", key_type, description);
|
||||||
free(key_type);
|
free(key_type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *tmp;
|
char *tmp;
|
||||||
asprintf(&tmp, "%s%-40s - %s\n", usage_str, key_type, description);
|
sasprintf(&tmp, "%s%-40s - %s\n", usage_str, key_type, description);
|
||||||
free(key_type);
|
free(key_type);
|
||||||
|
|
||||||
free(usage_str);
|
free(usage_str);
|
||||||
|
16
utils.c
16
utils.c
@ -55,9 +55,9 @@ char *string_append(char *a, const char *b, const char *sep)
|
|||||||
|
|
||||||
char *new;
|
char *new;
|
||||||
if (!sep)
|
if (!sep)
|
||||||
asprintf(&new, "%s%s", a, b);
|
sasprintf(&new, "%s%s", a, b);
|
||||||
else
|
else
|
||||||
asprintf(&new, "%s%s%s", a, sep, b);
|
sasprintf(&new, "%s%s%s", a, sep, b);
|
||||||
free(a);
|
free(a);
|
||||||
|
|
||||||
return new;
|
return new;
|
||||||
@ -108,4 +108,16 @@ void die(char *text, int exit_value)
|
|||||||
exit(exit_value);
|
exit(exit_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int sasprintf(char **strp, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
va_start(args, fmt);
|
||||||
|
if ((result = vasprintf(strp, fmt, args)) == -1)
|
||||||
|
die("asprintf failed", EXIT_FAILURE);
|
||||||
|
va_end(args);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/* vim: set ts=8 sw=8 tw=0: */
|
/* vim: set ts=8 sw=8 tw=0: */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user