strdup -> g_strdup

This commit is contained in:
Sascha Kruse 2013-02-16 10:18:26 +01:00
parent 34714fe1f9
commit ba09fa21f9
5 changed files with 27 additions and 26 deletions

View File

@ -26,7 +26,7 @@ void str_array_dup_append(str_array *a, const char *str)
{
if (!a)
return;
char *dup = strdup(str);
char *dup = g_strdup(str);
str_array_append(a, dup);
}

12
dunst.c
View File

@ -528,7 +528,7 @@ void r_line_cache_append(r_line_cache *c, const char *s, ColorSet *col, bool is_
c->count++;
c->lines[c->count-1].colors = col;
c->lines[c->count-1].str = strdup(s);
c->lines[c->count-1].str = g_strdup(s);
c->lines[c->count-1].is_begin = is_begin;
c->lines[c->count-1].is_end = is_end;
}
@ -595,7 +595,7 @@ void add_notification_to_line_cache(notification *n, int max_width)
if (n->dup_count > 0) {
buf = g_strdup_printf("(%d) %s", n->dup_count, msg);
} else {
buf = strdup(msg);
buf = g_strdup(msg);
}
/* print age */
@ -1083,7 +1083,7 @@ int init_notification(notification * n, int id)
apply_rules(n);
n->msg = string_replace("%a", n->appname, strdup(n->format));
n->msg = string_replace("%a", n->appname, g_strdup(n->format));
n->msg = string_replace("%s", n->summary, n->msg);
if (n->icon) {
n->msg = string_replace("%I", basename(n->icon), n->msg);
@ -1261,7 +1261,7 @@ void init_shortcut(keyboard_shortcut * ks)
return;
}
char *str = strdup(ks->str);
char *str = g_strdup(ks->str);
char *str_begin = str;
if (str == NULL)
@ -1725,7 +1725,7 @@ void load_options(char *cmdline_config_path)
sep_color = FRAME;
else {
sep_color = CUSTOM;
sep_custom_color_str = strdup(c);
sep_custom_color_str = g_strdup(c);
}
free(c);
}
@ -1827,7 +1827,7 @@ void load_options(char *cmdline_config_path)
initrule(r);
}
r->name = strdup(cur_section);
r->name = g_strdup(cur_section);
r->appname = ini_get_string(cur_section, "appname", r->appname);
r->summary = ini_get_string(cur_section, "summary", r->summary);
r->body = ini_get_string(cur_section, "body", r->body);

View File

@ -1,5 +1,6 @@
/* copyright 2013 Sascha Kruse and contributors (see LICENSE for licensing information) */
#include <glib.h>
#include <dbus/dbus.h>
#include "dunst.h"
@ -358,19 +359,19 @@ void notify(DBusMessage * dmsg)
expires = 1;
}
}
n->appname = appname != NULL ? strdup(appname) : "";
n->summary = summary != NULL ? strdup(summary) : "";
n->body = body != NULL ? strdup(body) : "";
n->icon = icon != NULL ? strdup(icon) : "";
n->appname = appname != NULL ? g_strdup(appname) : "";
n->summary = summary != NULL ? g_strdup(summary) : "";
n->body = body != NULL ? g_strdup(body) : "";
n->icon = icon != NULL ? g_strdup(icon) : "";
n->timeout = expires;
n->progress = (progress < 0 || progress > 100) ? 0 : progress + 1;
n->urgency = urgency;
n->dbus_client = strdup(dbus_message_get_sender(dmsg));
n->dbus_client = g_strdup(dbus_message_get_sender(dmsg));
for (i = 0; i < ColLast; i++) {
n->color_strings[i] = NULL;
}
n->color_strings[ColFG] = fgcolor == NULL ? NULL : strdup(fgcolor);
n->color_strings[ColBG] = bgcolor == NULL ? NULL : strdup(bgcolor);
n->color_strings[ColFG] = fgcolor == NULL ? NULL : g_strdup(fgcolor);
n->color_strings[ColBG] = bgcolor == NULL ? NULL : g_strdup(bgcolor);
id = init_notification(n, replaces_id);
if (id > 0)

View File

@ -43,7 +43,7 @@ section_t *new_section(char *name)
{
section_count++;
sections = realloc(sections, sizeof(section_t) * section_count);
sections[section_count - 1].name = strdup(name);
sections[section_count - 1].name = g_strdup(name);
sections[section_count - 1].entries = NULL;
sections[section_count - 1].entry_count = 0;
return &sections[section_count - 1];
@ -82,7 +82,7 @@ void add_entry(char *section_name, char *key, char *value)
s->entry_count++;
int len = s->entry_count;
s->entries = realloc(s->entries, sizeof(entry_t) * len);
s->entries[s->entry_count - 1].key = strdup(key);
s->entries[s->entry_count - 1].key = g_strdup(key);
s->entries[s->entry_count - 1].value = clean_value(value);
}
@ -105,12 +105,12 @@ char *ini_get_string(char *section, char *key, const char *def)
{
char *value = get_value(section, key);
if (value)
return strdup(value);
return g_strdup(value);
if (def == NULL)
return NULL;
else
return def ? strdup(def) : NULL;
return def ? g_strdup(def) : NULL;
}
int ini_get_int(char *section, char *key, int def)
@ -181,9 +181,9 @@ char *clean_value(char *value)
char *s;
if (value[0] == '"')
s = strdup(value + 1);
s = g_strdup(value + 1);
else
s = strdup(value);
s = g_strdup(value);
if (s[strlen(s) - 1] == '"')
s[strlen(s) - 1] = '\0';
@ -220,7 +220,7 @@ int load_ini_file(FILE * fp)
if (current_section)
free(current_section);
current_section = (strdup(start + 1));
current_section = (g_strdup(start + 1));
new_section(current_section);
continue;
}
@ -283,7 +283,7 @@ int cmdline_find_option(char *key)
if (!key) {
return -1;
}
char *key1 = strdup(key);
char *key1 = g_strdup(key);
char *key2 = strstr(key1, "/");
if (key2) {
@ -335,11 +335,11 @@ char *cmdline_get_string(char *key, const char *def, char *description)
char *str = cmdline_get_value(key);
if (str)
return strdup(str);
return g_strdup(str);
if (def == NULL)
return NULL;
else
return strdup(def);
return g_strdup(def);
}
int cmdline_get_int(char *key, int def, char *description)
@ -460,7 +460,7 @@ void cmdline_usage_append(char *key, char *type, char *description)
char *cmdline_create_usage(void)
{
return strdup(usage_str);
return g_strdup(usage_str);
}
/* vim: set ts=8 sw=8 tw=0: */

View File

@ -47,7 +47,7 @@ char *string_replace(const char *needle, const char *replacement,
char *string_append(char *a, const char *b, const char *sep)
{
if (!a)
return strdup(b);
return g_strdup(b);
char *new;
if (!sep)