aboutsummaryrefslogtreecommitdiff
path: root/libpam
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@stoeckmann.org>2023-12-06 20:03:34 +0100
committerDmitry V. Levin <ldv@strace.io>2023-12-06 19:03:34 +0000
commitf1ed3f00e2542cac4983a4bdc3edab3ae2646ddc (patch)
tree3fae140f6e8eba560a6f6edbbcde8524ab632350 /libpam
parent66cb44437a5453e0b5eeffa20cf7c5b42f721279 (diff)
downloadpam-f1ed3f00e2542cac4983a4bdc3edab3ae2646ddc.tar.gz
pam-f1ed3f00e2542cac4983a4bdc3edab3ae2646ddc.tar.bz2
pam-f1ed3f00e2542cac4983a4bdc3edab3ae2646ddc.zip
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 <tobias@stoeckmann.org>
Diffstat (limited to 'libpam')
-rw-r--r--libpam/pam_misc.c17
1 files 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 <syslog.h>
#include <ctype.h>
+#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 */
}