Commit 95b006c2 authored by Thomas Haller's avatar Thomas Haller
Browse files

dns: refactor create_resolv_conf() to use GString for constructing content

parent 20a7e489
......@@ -586,49 +586,42 @@ create_resolv_conf (char **searches,
char **nameservers,
char **options)
{
gs_free char *searches_str = NULL;
gs_free char *nameservers_str = NULL;
gs_free char *options_str = NULL;
char *tmp_str;
GString *str;
int i;
gsize i;
if (searches) {
tmp_str = g_strjoinv (" ", searches);
searches_str = g_strconcat ("search ", tmp_str, "\n", NULL);
g_free (tmp_str);
}
str = g_string_new_len ("# Generated by NetworkManager\n", 245);
if (options) {
tmp_str = g_strjoinv (" ", options);
options_str = g_strconcat ("options ", tmp_str, "\n", NULL);
g_free (tmp_str);
if (searches && searches[0]) {
g_string_append (str, "search");
for (i = 0; searches[i]; i++) {
g_string_append_c (str, ' ');
g_string_append (str, searches[i]);
}
g_string_append_c (str, '\n');
}
if (nameservers) {
int num = g_strv_length (nameservers);
str = g_string_new ("");
for (i = 0; i < num; i++) {
if (nameservers && nameservers[0]) {
for (i = 0; nameservers[i]; i++) {
if (i == 3) {
g_string_append (str, "# ");
g_string_append (str, "NOTE: the libc resolver may not support more than 3 nameservers.");
g_string_append (str, "\n# ");
g_string_append (str, "The nameservers listed below may not be recognized.");
g_string_append_c (str, '\n');
g_string_append (str, "# NOTE: the libc resolver may not support more than 3 nameservers.\n");
g_string_append (str, "# The nameservers listed below may not be recognized.\n");
}
g_string_append (str, "nameserver ");
g_string_append (str, nameservers[i]);
g_string_append_c (str, '\n');
}
nameservers_str = g_string_free (str, FALSE);
}
return g_strdup_printf ("# Generated by NetworkManager\n%s%s%s",
searches_str ?: "",
nameservers_str ?: "",
options_str ?: "");
if (options && options[0]) {
g_string_append (str, "options");
for (i = 0; options[i]; i++) {
g_string_append_c (str, ' ');
g_string_append (str, options[i]);
}
g_string_append_c (str, '\n');
}
return g_string_free (str, FALSE);
}
static gboolean
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment