From f1ed3f00e2542cac4983a4bdc3edab3ae2646ddc Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Wed, 6 Dec 2023 20:03:34 +0100 Subject: libpam: simplify _pam_tokenize internals Since format is a constant, the table can be skipped. Use strspn/strcspn instead which might even be optimized compared to custom for loops. Signed-off-by: Tobias Stoeckmann --- libpam/pam_misc.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/libpam/pam_misc.c b/libpam/pam_misc.c index 88702fcc..f0b35c28 100644 --- a/libpam/pam_misc.c +++ b/libpam/pam_misc.c @@ -45,6 +45,8 @@ #include #include +#define DELIMITERS " \n\t" + char *_pam_tokenize(char *from, char **next) /* * this function is a variant of the standard strtok_r, it differs in that @@ -52,22 +54,13 @@ char *_pam_tokenize(char *from, char **next) * they are actually reached. */ { - const char *format = " \n\t"; - char table[256], *end; - int i; + char *end; if (from == NULL && (from = *next) == NULL) return from; - /* initialize table */ - for (i=1; i<256; table[i++] = '\0'); - for (i=0; format[i] ; - table[(unsigned char)format[i++]] = 'y'); - /* look for first non-format char */ - while (*from && table[(unsigned char)*from]) { - ++from; - } + from += strspn(from, DELIMITERS); if (*from == '[') { /* @@ -93,7 +86,7 @@ char *_pam_tokenize(char *from, char **next) remains */ } else if (*from) { /* simply look for next blank char */ - for (end=from; *end && !table[(unsigned char)*end]; ++end); + end = from + strcspn(from, DELIMITERS); } else { return (*next = NULL); /* no tokens left */ } -- cgit v1.2.3