lib/, src/: Use stpsep() instead of its pattern

Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2024-07-08 20:25:01 -05:00
committed by Serge Hallyn
parent 39da15614e
commit d91b22cc2f
20 changed files with 69 additions and 85 deletions
+2 -1
View File
@@ -36,6 +36,7 @@
#include "shadowlog_internal.h"
#include "sssd.h"
#include "string/sprintf/snprintf.h"
#include "string/strtok/stpsep.h"
/* local function prototypes */
@@ -659,7 +660,7 @@ int commonio_open (struct commonio_db *db, int mode)
goto cleanup_buf;
}
}
stpcpy(strchrnul(buf, '\n'), "");
stpsep(buf, "\n");
line = strdup (buf);
if (NULL == line) {
+2 -3
View File
@@ -17,8 +17,7 @@
#include "getdef.h"
#include "prototypes.h"
#include "string/strcpy/strtcpy.h"
#ident "$Id$"
#include "string/strtok/stpsep.h"
/*
@@ -76,7 +75,7 @@ static bool is_listed (const char *cfgin, const char *tty, bool def)
*/
while (fgets (buf, sizeof (buf), fp) != NULL) {
stpcpy(strchrnul(buf, '\n'), "");
stpsep(buf, "\n");
if (strcmp (buf, tty) == 0) {
(void) fclose (fp);
return true;
+2 -4
View File
@@ -17,6 +17,7 @@
#include "prototypes.h"
#include "string/strchr/strrspn.h"
#include "string/strtok/stpsep.h"
/*
@@ -80,11 +81,8 @@ void change_field (char *buf, size_t maxsize, const char *prompt)
return;
}
cp = strchr (newf, '\n');
if (NULL == cp) {
if (stpsep(newf, "\n") == NULL)
return;
}
stpcpy(cp, "");
if ('\0' != newf[0]) {
/*
+4 -5
View File
@@ -29,9 +29,9 @@
#include "prototypes.h"
#include "shadowlog_internal.h"
#include "string/sprintf/xasprintf.h"
#include "string/strchr/stpcspn.h"
#include "string/strchr/stpspn.h"
#include "string/strchr/strrspn.h"
#include "string/strtok/stpsep.h"
/*
@@ -569,13 +569,12 @@ static void def_load (void)
if (*name == '\0' || *name == '#')
continue; /* comment or empty */
s = stpcspn(name, " \t"); /* end of field */
if (*s == '\0')
s = stpsep(name, " \t"); /* next field */
if (s == NULL)
continue; /* only 1 field?? */
stpcpy(s++, "");
value = stpspn(s, " \"\t"); /* next nonwhite */
stpcpy(strchrnul(value, '"'), "");
stpsep(value, "\"");
/*
* Store the value in def_table.
+5 -3
View File
@@ -20,8 +20,10 @@
#include "alloc/malloc.h"
#include "alloc/realloc.h"
#include "alloc/x/xrealloc.h"
#include "prototypes.h"
#include "defines.h"
#include "prototypes.h"
#include "string/strtok/stpsep.h"
static /*@null@*/FILE *shadow;
static /*@null@*//*@only@*/char **members = NULL;
@@ -91,7 +93,7 @@ void endsgent (void)
}
strcpy (sgrbuf, string);
stpcpy(strchrnul(sgrbuf, '\n'), "");
stpsep(sgrbuf, "\n");
/*
* There should be exactly 4 colon separated fields. Find
@@ -172,7 +174,7 @@ void endsgent (void)
return NULL;
}
}
stpcpy(strchrnul(buf, '\n'), "");
stpsep(buf, "\n");
return (sgetsgent (buf));
}
return NULL;
+2 -1
View File
@@ -21,6 +21,7 @@
#include "getdef.h"
#include "prototypes.h"
#include "string/sprintf/snprintf.h"
#include "string/strtok/stpsep.h"
/*
@@ -72,7 +73,7 @@ bool hushed (const char *username)
return false;
}
for (found = false; !found && (fgets (buf, sizeof buf, fp) == buf);) {
stpcpy(strchrnul(buf, '\n'), "");
stpsep(buf, "\n");
found = (strcmp (buf, pw->pw_shell) == 0) ||
(strcmp (buf, pw->pw_name) == 0);
}
+6 -7
View File
@@ -16,10 +16,12 @@
#include <signal.h>
#include "attr.h"
#include "memzero.h"
#include "prototypes.h"
#include "defines.h"
#include "getdef.h"
#include "memzero.h"
#include "prototypes.h"
#include "string/strtok/stpsep.h"
static void login_exit (MAYBE_UNUSED int sig)
{
@@ -83,11 +85,8 @@ void login_prompt (char *name, int namesize)
exit (EXIT_FAILURE);
}
cp = strchr (buf, '\n');
if (NULL == cp) {
exit (EXIT_FAILURE);
}
stpcpy(cp, ""); /* remove \n [ must be there ] */
if (stpsep(buf, "\n") == NULL)
exit(EXIT_FAILURE);
/*
* Skip leading whitespace. This makes " username" work right.
+2 -1
View File
@@ -19,6 +19,7 @@
#include "defines.h"
#include "port.h"
#include "prototypes.h"
#include "string/strtok/stpsep.h"
static FILE *ports;
@@ -142,7 +143,7 @@ next:
if ('#' == buf[0])
goto next;
stpcpy(strchrnul(buf, '\n'), "");
stpsep(buf, "\n");
field = buf;
+6 -12
View File
@@ -28,6 +28,7 @@
#include "shadowlog.h"
#include "string/sprintf/xasprintf.h"
#include "string/strdup/xstrdup.h"
#include "string/strtok/stpsep.h"
#ifndef USE_PAM
@@ -52,11 +53,8 @@ static void read_env_file (const char *filename)
return;
}
while (fgets (buf, (int)(sizeof buf), fp) == buf) {
cp = strrchr (buf, '\n');
if (NULL == cp) {
if (stpsep(buf, "\n") == NULL)
break;
}
stpcpy(cp, "");
cp = buf;
/* ignore whitespace and comments */
@@ -71,15 +69,11 @@ static void read_env_file (const char *filename)
* (for example, the "export NAME" shell commands)
*/
name = cp;
while (('\0' != *cp) && !isspace (*cp) && ('=' != *cp)) {
cp++;
}
if ('=' != *cp) {
val = stpsep(cp, "=");
if (val == NULL)
continue;
if (strpbrk(name, " \t") != NULL)
continue;
}
/* NUL-terminate the name */
stpcpy(cp++, "");
val = cp;
#if 0 /* XXX untested, and needs rewrite with fewer goto's :-) */
/*
(state, char_type) -> (state, action)
+2 -1
View File
@@ -21,6 +21,7 @@
#include "atoi/getnum.h"
#include "defines.h"
#include "prototypes.h"
#include "string/strtok/stpsep.h"
#define NFIELDS 4
@@ -83,7 +84,7 @@ struct group *sgetgrent (const char *buf)
}
}
strcpy (grpbuf, buf);
stpcpy(strchrnul(grpbuf, '\n'), "");
stpsep(grpbuf, "\n");
for (cp = grpbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++)
grpfields[i] = strsep(&cp, ":");
+3 -2
View File
@@ -21,9 +21,10 @@
#include "atoi/a2i.h"
#include "atoi/str2i.h"
#include "defines.h"
#include "prototypes.h"
#include "shadowlog_internal.h"
#include "defines.h"
#include "string/strtok/stpsep.h"
#define FIELDS 9
@@ -54,7 +55,7 @@ sgetspent(const char *string)
return NULL; /* fail if too long */
}
strcpy (spwbuf, string);
stpcpy(strchrnul(spwbuf, '\n'), "");
stpsep(spwbuf, "\n");
/*
* Tokenize the string into colon separated fields. Allow up to
+3 -2
View File
@@ -22,6 +22,7 @@
#include "atoi/str2i.h"
#include "defines.h"
#include "prototypes.h"
#include "string/strtok/stpsep.h"
static FILE *shadow;
@@ -77,7 +78,7 @@ static struct spwd *my_sgetspent (const char *string)
if (strlen (string) >= sizeof spwbuf)
return 0;
strcpy (spwbuf, string);
stpcpy(strchrnul(spwbuf, '\n'), "");
stpsep(spwbuf, "\n");
/*
* Tokenize the string into colon separated fields. Allow up to
@@ -202,7 +203,7 @@ struct spwd *fgetspent (FILE * fp)
if (fgets (buf, sizeof buf, fp) != NULL)
{
stpcpy(strchrnul(buf, '\n'), "");
stpsep(buf, "\n");
return my_sgetspent (buf);
}
return 0;
+2 -1
View File
@@ -17,6 +17,7 @@
#include "defines.h"
#include "getdef.h"
#include "prototypes.h"
#include "string/strtok/stpsep.h"
/*
@@ -49,7 +50,7 @@ void ttytype (const char *line)
continue;
}
stpcpy(strchrnul(buf, '\n'), "");
stpsep(buf, "\n");
if ( (sscanf (buf, "%1023s %1023s", type, port) == 2)
&& (strcmp (line, port) == 0)) {
+5 -2
View File
@@ -16,9 +16,12 @@
#include <stdio.h>
#include <string.h>
#include "defines.h"
#include "prototypes.h"
#include "getdef.h"
#include "prototypes.h"
#include "string/strtok/stpsep.h"
/*
* tz - return local timezone name
@@ -42,7 +45,7 @@
strcpy (tzbuf, def_tz);
} else {
stpcpy(strchrnul(tzbuf, '\n'), "");
stpsep(tzbuf, "\n");
}
if (NULL != fp) {