diff --git a/lib/fields.c b/lib/fields.c index 53929248..b6d2fa14 100644 --- a/lib/fields.c +++ b/lib/fields.c @@ -14,7 +14,10 @@ #include #include #include + #include "prototypes.h" +#include "string/strchr/strrspn.h" + /* * valid_field - insure that a field contains all legal characters @@ -89,11 +92,7 @@ void change_field (char *buf, size_t maxsize, const char *prompt) * makes it possible to change the field to empty, by * entering a space. --marekm */ - - while (newf < cp && isspace (cp[-1])) { - cp--; - } - *cp = '\0'; + *strrspn(newf, " \t\n") = '\0'; cp = newf; while (isspace (*cp)) { diff --git a/lib/getdef.c b/lib/getdef.c index 459fdc99..91f40702 100644 --- a/lib/getdef.c +++ b/lib/getdef.c @@ -31,6 +31,7 @@ #include "string/sprintf/xasprintf.h" #include "string/strchr/stpcspn.h" #include "string/strchr/stpspn.h" +#include "string/strchr/strrspn.h" /* @@ -528,7 +529,6 @@ static void def_load (void) #else /* USE_ECONF */ static void def_load (void) { - int i; FILE *fp; char buf[1024], *name, *value, *s; @@ -560,13 +560,7 @@ static void def_load (void) /* * Trim trailing whitespace. */ - for (i = (ptrdiff_t) strlen (buf) - 1; i >= 0; --i) { - if (!isspace (buf[i])) { - break; - } - } - i++; - buf[i] = '\0'; + *strrspn(buf, " \t\n") = '\0'; /* * Break the line into two fields. diff --git a/src/login_nopam.c b/src/login_nopam.c index 1a2b1736..03a2871f 100644 --- a/src/login_nopam.c +++ b/src/login_nopam.c @@ -57,6 +57,7 @@ #include /* for inet_ntoa() */ #include "sizeof.h" +#include "string/strchr/strrspn.h" #if !defined(MAXHOSTNAMELEN) || (MAXHOSTNAMELEN < 64) #undef MAXHOSTNAMELEN @@ -110,10 +111,7 @@ int login_access (const char *user, const char *from) if (line[0] == '#') { continue; /* comment line */ } - while (end > 0 && isspace (line[end - 1])) { - end--; - } - line[end] = '\0'; /* strip trailing whitespace */ + *strrspn(line, " \t\n") = '\0'; if (line[0] == '\0') { /* skip blank lines */ continue; } diff --git a/src/suauth.c b/src/suauth.c index 4d631904..ed45a856 100644 --- a/src/suauth.c +++ b/src/suauth.c @@ -8,13 +8,17 @@ */ #include + #include #include #include #include #include + #include "defines.h" #include "prototypes.h" +#include "string/strchr/strrspn.h" + #ifndef SUAUTHFILE #define SUAUTHFILE "/etc/suauth" @@ -77,11 +81,7 @@ int check_su_auth (const char *actual_id, continue; } - while (endline > 0 && (temp[endline - 1] == ' ' - || temp[endline - 1] == '\t' - || temp[endline - 1] == '\n')) - endline--; - temp[endline] = '\0'; + *strrspn(temp, " \t\n") = '\0'; posn = 0; while (temp[posn] == ' ' || temp[posn] == '\t')