settings: refactor read_hostname_*()
This commit is contained in:
@@ -480,27 +480,25 @@ get_plugin (NMSettings *self, guint32 capability)
|
|||||||
static gchar *
|
static gchar *
|
||||||
read_hostname_gentoo (const char *path)
|
read_hostname_gentoo (const char *path)
|
||||||
{
|
{
|
||||||
gchar *contents = NULL, *result = NULL, *tmp;
|
gs_free char *contents = NULL;
|
||||||
gchar **all_lines = NULL;
|
gs_strfreev char **all_lines = NULL;
|
||||||
guint line_num, i;
|
const char *tmp;
|
||||||
|
guint i;
|
||||||
|
|
||||||
if (!g_file_get_contents (path, &contents, NULL, NULL))
|
if (!g_file_get_contents (path, &contents, NULL, NULL))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
all_lines = g_strsplit (contents, "\n", 0);
|
all_lines = g_strsplit (contents, "\n", 0);
|
||||||
line_num = g_strv_length (all_lines);
|
for (i = 0; all_lines[i]; i++) {
|
||||||
for (i = 0; i < line_num; i++) {
|
|
||||||
g_strstrip (all_lines[i]);
|
g_strstrip (all_lines[i]);
|
||||||
if (all_lines[i][0] == '#' || all_lines[i][0] == '\0')
|
if (all_lines[i][0] == '#' || all_lines[i][0] == '\0')
|
||||||
continue;
|
continue;
|
||||||
if (g_str_has_prefix (all_lines[i], "hostname=")) {
|
if (g_str_has_prefix (all_lines[i], "hostname=")) {
|
||||||
tmp = &all_lines[i][NM_STRLEN ("hostname=")];
|
tmp = &all_lines[i][NM_STRLEN ("hostname=")];
|
||||||
result = g_shell_unquote (tmp, NULL);
|
return g_shell_unquote (tmp, NULL);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_strfreev (all_lines);
|
return NULL;
|
||||||
g_free (contents);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -508,15 +506,16 @@ read_hostname_gentoo (const char *path)
|
|||||||
static gchar *
|
static gchar *
|
||||||
read_hostname_slackware (const char *path)
|
read_hostname_slackware (const char *path)
|
||||||
{
|
{
|
||||||
gchar *contents = NULL, *result = NULL, *tmp;
|
gs_free char *contents = NULL;
|
||||||
gchar **all_lines = NULL;
|
gs_strfreev char **all_lines = NULL;
|
||||||
guint line_num, i, j = 0;
|
char *tmp;
|
||||||
|
guint i, j = 0;
|
||||||
|
|
||||||
if (!g_file_get_contents (path, &contents, NULL, NULL))
|
if (!g_file_get_contents (path, &contents, NULL, NULL))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
all_lines = g_strsplit (contents, "\n", 0);
|
all_lines = g_strsplit (contents, "\n", 0);
|
||||||
line_num = g_strv_length (all_lines);
|
for (i = 0; all_lines[i]; i++) {
|
||||||
for (i = 0; i < line_num; i++) {
|
|
||||||
g_strstrip (all_lines[i]);
|
g_strstrip (all_lines[i]);
|
||||||
if (all_lines[i][0] == '#' || all_lines[i][0] == '\0')
|
if (all_lines[i][0] == '#' || all_lines[i][0] == '\0')
|
||||||
continue;
|
continue;
|
||||||
@@ -530,12 +529,9 @@ read_hostname_slackware (const char *path)
|
|||||||
}
|
}
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
result = g_shell_unquote (tmp, NULL);
|
return g_shell_unquote (tmp, NULL);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
g_strfreev (all_lines);
|
return NULL;
|
||||||
g_free (contents);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user