Skip to content

Commit d91b22c

Browse files
alejandro-colomarhallyn
authored andcommitted
lib/, src/: Use stpsep() instead of its pattern
Signed-off-by: Alejandro Colomar <[email protected]>
1 parent 39da156 commit d91b22c

20 files changed

+69
-85
lines changed

lib/commonio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "shadowlog_internal.h"
3737
#include "sssd.h"
3838
#include "string/sprintf/snprintf.h"
39+
#include "string/strtok/stpsep.h"
3940

4041

4142
/* local function prototypes */
@@ -659,7 +660,7 @@ int commonio_open (struct commonio_db *db, int mode)
659660
goto cleanup_buf;
660661
}
661662
}
662-
stpcpy(strchrnul(buf, '\n'), "");
663+
stpsep(buf, "\n");
663664

664665
line = strdup (buf);
665666
if (NULL == line) {

lib/console.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
#include "getdef.h"
1818
#include "prototypes.h"
1919
#include "string/strcpy/strtcpy.h"
20-
21-
#ident "$Id$"
20+
#include "string/strtok/stpsep.h"
2221

2322

2423
/*
@@ -76,7 +75,7 @@ static bool is_listed (const char *cfgin, const char *tty, bool def)
7675
*/
7776

7877
while (fgets (buf, sizeof (buf), fp) != NULL) {
79-
stpcpy(strchrnul(buf, '\n'), "");
78+
stpsep(buf, "\n");
8079
if (strcmp (buf, tty) == 0) {
8180
(void) fclose (fp);
8281
return true;

lib/fields.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "prototypes.h"
1919
#include "string/strchr/strrspn.h"
20+
#include "string/strtok/stpsep.h"
2021

2122

2223
/*
@@ -80,11 +81,8 @@ void change_field (char *buf, size_t maxsize, const char *prompt)
8081
return;
8182
}
8283

83-
cp = strchr (newf, '\n');
84-
if (NULL == cp) {
84+
if (stpsep(newf, "\n") == NULL)
8585
return;
86-
}
87-
stpcpy(cp, "");
8886

8987
if ('\0' != newf[0]) {
9088
/*

lib/getdef.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
#include "prototypes.h"
3030
#include "shadowlog_internal.h"
3131
#include "string/sprintf/xasprintf.h"
32-
#include "string/strchr/stpcspn.h"
3332
#include "string/strchr/stpspn.h"
3433
#include "string/strchr/strrspn.h"
34+
#include "string/strtok/stpsep.h"
3535

3636

3737
/*
@@ -569,13 +569,12 @@ static void def_load (void)
569569
if (*name == '\0' || *name == '#')
570570
continue; /* comment or empty */
571571

572-
s = stpcspn(name, " \t"); /* end of field */
573-
if (*s == '\0')
572+
s = stpsep(name, " \t"); /* next field */
573+
if (s == NULL)
574574
continue; /* only 1 field?? */
575575

576-
stpcpy(s++, "");
577576
value = stpspn(s, " \"\t"); /* next nonwhite */
578-
stpcpy(strchrnul(value, '"'), "");
577+
stpsep(value, "\"");
579578

580579
/*
581580
* Store the value in def_table.

lib/gshadow.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
#include "alloc/malloc.h"
2121
#include "alloc/realloc.h"
2222
#include "alloc/x/xrealloc.h"
23-
#include "prototypes.h"
2423
#include "defines.h"
24+
#include "prototypes.h"
25+
#include "string/strtok/stpsep.h"
26+
2527

2628
static /*@null@*/FILE *shadow;
2729
static /*@null@*//*@only@*/char **members = NULL;
@@ -91,7 +93,7 @@ void endsgent (void)
9193
}
9294

9395
strcpy (sgrbuf, string);
94-
stpcpy(strchrnul(sgrbuf, '\n'), "");
96+
stpsep(sgrbuf, "\n");
9597

9698
/*
9799
* There should be exactly 4 colon separated fields. Find
@@ -172,7 +174,7 @@ void endsgent (void)
172174
return NULL;
173175
}
174176
}
175-
stpcpy(strchrnul(buf, '\n'), "");
177+
stpsep(buf, "\n");
176178
return (sgetsgent (buf));
177179
}
178180
return NULL;

lib/hushed.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "getdef.h"
2222
#include "prototypes.h"
2323
#include "string/sprintf/snprintf.h"
24+
#include "string/strtok/stpsep.h"
2425

2526

2627
/*
@@ -72,7 +73,7 @@ bool hushed (const char *username)
7273
return false;
7374
}
7475
for (found = false; !found && (fgets (buf, sizeof buf, fp) == buf);) {
75-
stpcpy(strchrnul(buf, '\n'), "");
76+
stpsep(buf, "\n");
7677
found = (strcmp (buf, pw->pw_shell) == 0) ||
7778
(strcmp (buf, pw->pw_name) == 0);
7879
}

lib/loginprompt.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
#include <signal.h>
1717

1818
#include "attr.h"
19-
#include "memzero.h"
20-
#include "prototypes.h"
2119
#include "defines.h"
2220
#include "getdef.h"
21+
#include "memzero.h"
22+
#include "prototypes.h"
23+
#include "string/strtok/stpsep.h"
24+
2325

2426
static void login_exit (MAYBE_UNUSED int sig)
2527
{
@@ -83,11 +85,8 @@ void login_prompt (char *name, int namesize)
8385
exit (EXIT_FAILURE);
8486
}
8587

86-
cp = strchr (buf, '\n');
87-
if (NULL == cp) {
88-
exit (EXIT_FAILURE);
89-
}
90-
stpcpy(cp, ""); /* remove \n [ must be there ] */
88+
if (stpsep(buf, "\n") == NULL)
89+
exit(EXIT_FAILURE);
9190

9291
/*
9392
* Skip leading whitespace. This makes " username" work right.

lib/port.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "defines.h"
2020
#include "port.h"
2121
#include "prototypes.h"
22+
#include "string/strtok/stpsep.h"
2223

2324

2425
static FILE *ports;
@@ -142,7 +143,7 @@ getportent(void)
142143
if ('#' == buf[0])
143144
goto next;
144145

145-
stpcpy(strchrnul(buf, '\n'), "");
146+
stpsep(buf, "\n");
146147

147148
field = buf;
148149

lib/setupenv.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "shadowlog.h"
2929
#include "string/sprintf/xasprintf.h"
3030
#include "string/strdup/xstrdup.h"
31+
#include "string/strtok/stpsep.h"
3132

3233

3334
#ifndef USE_PAM
@@ -52,11 +53,8 @@ static void read_env_file (const char *filename)
5253
return;
5354
}
5455
while (fgets (buf, (int)(sizeof buf), fp) == buf) {
55-
cp = strrchr (buf, '\n');
56-
if (NULL == cp) {
56+
if (stpsep(buf, "\n") == NULL)
5757
break;
58-
}
59-
stpcpy(cp, "");
6058

6159
cp = buf;
6260
/* ignore whitespace and comments */
@@ -71,15 +69,11 @@ static void read_env_file (const char *filename)
7169
* (for example, the "export NAME" shell commands)
7270
*/
7371
name = cp;
74-
while (('\0' != *cp) && !isspace (*cp) && ('=' != *cp)) {
75-
cp++;
76-
}
77-
if ('=' != *cp) {
72+
val = stpsep(cp, "=");
73+
if (val == NULL)
74+
continue;
75+
if (strpbrk(name, " \t") != NULL)
7876
continue;
79-
}
80-
/* NUL-terminate the name */
81-
stpcpy(cp++, "");
82-
val = cp;
8377
#if 0 /* XXX untested, and needs rewrite with fewer goto's :-) */
8478
/*
8579
(state, char_type) -> (state, action)

lib/sgetgrent.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "atoi/getnum.h"
2222
#include "defines.h"
2323
#include "prototypes.h"
24+
#include "string/strtok/stpsep.h"
2425

2526

2627
#define NFIELDS 4
@@ -83,7 +84,7 @@ struct group *sgetgrent (const char *buf)
8384
}
8485
}
8586
strcpy (grpbuf, buf);
86-
stpcpy(strchrnul(grpbuf, '\n'), "");
87+
stpsep(grpbuf, "\n");
8788

8889
for (cp = grpbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++)
8990
grpfields[i] = strsep(&cp, ":");

lib/sgetspent.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121

2222
#include "atoi/a2i.h"
2323
#include "atoi/str2i.h"
24+
#include "defines.h"
2425
#include "prototypes.h"
2526
#include "shadowlog_internal.h"
26-
#include "defines.h"
27+
#include "string/strtok/stpsep.h"
2728

2829

2930
#define FIELDS 9
@@ -54,7 +55,7 @@ sgetspent(const char *string)
5455
return NULL; /* fail if too long */
5556
}
5657
strcpy (spwbuf, string);
57-
stpcpy(strchrnul(spwbuf, '\n'), "");
58+
stpsep(spwbuf, "\n");
5859

5960
/*
6061
* Tokenize the string into colon separated fields. Allow up to

lib/shadow.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "atoi/str2i.h"
2323
#include "defines.h"
2424
#include "prototypes.h"
25+
#include "string/strtok/stpsep.h"
2526

2627

2728
static FILE *shadow;
@@ -77,7 +78,7 @@ static struct spwd *my_sgetspent (const char *string)
7778
if (strlen (string) >= sizeof spwbuf)
7879
return 0;
7980
strcpy (spwbuf, string);
80-
stpcpy(strchrnul(spwbuf, '\n'), "");
81+
stpsep(spwbuf, "\n");
8182

8283
/*
8384
* Tokenize the string into colon separated fields. Allow up to
@@ -202,7 +203,7 @@ struct spwd *fgetspent (FILE * fp)
202203

203204
if (fgets (buf, sizeof buf, fp) != NULL)
204205
{
205-
stpcpy(strchrnul(buf, '\n'), "");
206+
stpsep(buf, "\n");
206207
return my_sgetspent (buf);
207208
}
208209
return 0;

lib/ttytype.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "defines.h"
1818
#include "getdef.h"
1919
#include "prototypes.h"
20+
#include "string/strtok/stpsep.h"
2021

2122

2223
/*
@@ -49,7 +50,7 @@ void ttytype (const char *line)
4950
continue;
5051
}
5152

52-
stpcpy(strchrnul(buf, '\n'), "");
53+
stpsep(buf, "\n");
5354

5455
if ( (sscanf (buf, "%1023s %1023s", type, port) == 2)
5556
&& (strcmp (line, port) == 0)) {

lib/tz.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616

1717
#include <stdio.h>
1818
#include <string.h>
19+
1920
#include "defines.h"
20-
#include "prototypes.h"
2121
#include "getdef.h"
22+
#include "prototypes.h"
23+
#include "string/strtok/stpsep.h"
24+
2225

2326
/*
2427
* tz - return local timezone name
@@ -42,7 +45,7 @@
4245

4346
strcpy (tzbuf, def_tz);
4447
} else {
45-
stpcpy(strchrnul(tzbuf, '\n'), "");
48+
stpsep(tzbuf, "\n");
4649
}
4750

4851
if (NULL != fp) {

src/chgpasswd.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
/*@-exitarg@*/
3535
#include "exitcodes.h"
3636
#include "shadowlog.h"
37+
#include "string/strtok/stpsep.h"
3738

3839

3940
/*
@@ -460,10 +461,7 @@ int main (int argc, char **argv)
460461
*/
461462
while (fgets (buf, (int) sizeof buf, stdin) != NULL) {
462463
line++;
463-
cp = strrchr (buf, '\n');
464-
if (NULL != cp) {
465-
stpcpy(cp, "");
466-
} else {
464+
if (stpsep(buf, "\n") == NULL) {
467465
fprintf (stderr, _("%s: line %d: line too long\n"),
468466
Prog, line);
469467
errors++;
@@ -480,11 +478,8 @@ int main (int argc, char **argv)
480478
*/
481479

482480
name = buf;
483-
cp = strchr (name, ':');
484-
if (NULL != cp) {
485-
stpcpy(cp, "");
486-
cp++;
487-
} else {
481+
cp = stpsep(name, ":");
482+
if (cp == NULL) {
488483
fprintf (stderr,
489484
_("%s: line %d: missing new password\n"),
490485
Prog, line);

src/chpasswd.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
/*@-exitarg@*/
3232
#include "exitcodes.h"
3333
#include "shadowlog.h"
34+
#include "string/strtok/stpsep.h"
3435

3536

3637
#define IS_CRYPT_METHOD(str) ((crypt_method != NULL && strcmp(crypt_method, str) == 0) ? true : false)
@@ -501,12 +502,8 @@ int main (int argc, char **argv)
501502
*/
502503
while (fgets (buf, sizeof buf, stdin) != NULL) {
503504
line++;
504-
cp = strrchr (buf, '\n');
505-
if (NULL != cp) {
506-
stpcpy(cp, "");
507-
} else {
505+
if (stpsep(buf, "\n") == NULL) {
508506
if (feof (stdin) == 0) {
509-
510507
// Drop all remaining characters on this line.
511508
while (fgets (buf, sizeof buf, stdin) != NULL) {
512509
cp = strchr (buf, '\n');
@@ -533,10 +530,8 @@ int main (int argc, char **argv)
533530
*/
534531

535532
name = buf;
536-
cp = strchr (name, ':');
537-
if (NULL != cp) {
538-
stpcpy(cp++, "");
539-
} else {
533+
cp = stpsep(name, ":");
534+
if (cp == NULL) {
540535
fprintf (stderr,
541536
_("%s: line %d: missing new password\n"),
542537
Prog, line);

0 commit comments

Comments
 (0)