diff options
author | Thomas Haller <thaller@redhat.com> | 2018-09-27 13:35:42 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-10-04 10:58:50 +0200 |
commit | 6c5f96b1c0bdb4e581c28176ee7fef44bf74429b (patch) | |
tree | 94567c30af831987e07e01bd4ec749f3b6b11fe7 | |
parent | df148096f79621fb508416563ccbb76098f0a923 (diff) |
keyfile: refactor check whether filename starts with a dot
check_prefix() was only ever called with "." as prefix.
Simplify the implementation to explicitly check for a leading
dot.
-rw-r--r-- | src/settings/plugins/keyfile/nms-keyfile-utils.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/settings/plugins/keyfile/nms-keyfile-utils.c b/src/settings/plugins/keyfile/nms-keyfile-utils.c index 2a183d2f1..3912e5d76 100644 --- a/src/settings/plugins/keyfile/nms-keyfile-utils.c +++ b/src/settings/plugins/keyfile/nms-keyfile-utils.c @@ -56,18 +56,11 @@ check_mkstemp_suffix (const char *path) } static gboolean -check_prefix (const char *base, const char *tag) +check_prefix_dot (const char *base) { - int len, tag_len; - - g_return_val_if_fail (base != NULL, TRUE); - g_return_val_if_fail (tag != NULL, TRUE); + nm_assert (base && base[0]); - len = strlen (base); - tag_len = strlen (tag); - if ((len > tag_len) && !g_ascii_strncasecmp (base, tag, tag_len)) - return TRUE; - return FALSE; + return base[0] == '.'; } static gboolean @@ -102,7 +95,7 @@ nms_keyfile_utils_should_ignore_file (const char *filename) /* Ignore hidden and backup files */ /* should_ignore_file() must mirror escape_filename() */ - if (check_prefix (base, ".") || check_suffix (base, "~")) + if (check_prefix_dot (base) || check_suffix (base, "~")) return TRUE; /* Ignore temporary files */ if (check_mkstemp_suffix (base)) @@ -198,7 +191,7 @@ nms_keyfile_utils_escape_filename (const char *filename) /* escape_filename() must avoid anything that should_ignore_file() would reject. * We can escape here more aggressivly then what we would read back. */ - if (check_prefix (str->str, ".")) + if (check_prefix_dot (str->str)) str->str[0] = ESCAPE_CHAR2; if (check_suffix (str->str, "~")) str->str[str->len - 1] = ESCAPE_CHAR2; |