From 7a8f1e66260ebe1d125d006d119f4e27ea821b3a Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Mon, 2 Dec 2024 13:23:49 +0100 Subject: [PATCH] lib/chkname.c: is_valid_name(): Use streq() instead of its pattern Signed-off-by: Alejandro Colomar --- lib/chkname.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/chkname.c b/lib/chkname.c index 8bde7a2d9..f9a284e45 100644 --- a/lib/chkname.c +++ b/lib/chkname.c @@ -31,8 +31,9 @@ #include #include -#include "defines.h" #include "chkname.h" +#include "defines.h" +#include "string/strcmp/streq.h" int allow_bad_names = false; @@ -70,9 +71,9 @@ is_valid_name(const char *name) */ int numeric; - if ('\0' == *name || - ('.' == *name && (('.' == name[1] && '\0' == name[2]) || - '\0' == name[1])) || + if (streq(name, "") || + streq(name, ".") || + streq(name, "..") || !((*name >= 'a' && *name <= 'z') || (*name >= 'A' && *name <= 'Z') || (*name >= '0' && *name <= '9') || @@ -92,7 +93,7 @@ is_valid_name(const char *name) *name == '_' || *name == '.' || *name == '-' || - (*name == '$' && name[1] == '\0') + streq(name, "$") )) { errno = EINVAL;