lib/, src/: Use strchrnul(3) instead of its pattern
In the files where #include <string.h> is missing, add it, and sort the includes. Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Serge Hallyn
parent
077f7b6ade
commit
964df6ed6e
@@ -11,28 +11,29 @@
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "defines.h"
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <utime.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "atoi/getnum.h"
|
||||
#include "commonio.h"
|
||||
#include "defines.h"
|
||||
#include "memzero.h"
|
||||
#include "nscd.h"
|
||||
#include "sssd.h"
|
||||
#ifdef WITH_TCB
|
||||
#include <tcb.h>
|
||||
#endif /* WITH_TCB */
|
||||
#include "prototypes.h"
|
||||
#include "commonio.h"
|
||||
#include "shadowlog_internal.h"
|
||||
#include "sssd.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
|
||||
|
||||
@@ -639,7 +640,6 @@ int commonio_open (struct commonio_db *db, int mode)
|
||||
goto cleanup_errno;
|
||||
|
||||
while (db->ops->fgets (buf, buflen, db->fp) == buf) {
|
||||
char *cp;
|
||||
struct commonio_entry *p;
|
||||
|
||||
while ( (strrchr (buf, '\n') == NULL)
|
||||
@@ -658,10 +658,7 @@ int commonio_open (struct commonio_db *db, int mode)
|
||||
goto cleanup_buf;
|
||||
}
|
||||
}
|
||||
cp = strrchr (buf, '\n');
|
||||
if (NULL != cp) {
|
||||
*cp = '\0';
|
||||
}
|
||||
*strchrnul(buf, '\n') = '\0';
|
||||
|
||||
line = strdup (buf);
|
||||
if (NULL == line) {
|
||||
|
||||
@@ -9,14 +9,18 @@
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include "defines.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "getdef.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/strcpy/strtcpy.h"
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
|
||||
/*
|
||||
* This is now rather generic function which decides if "tty" is listed
|
||||
* under "cfgin" in config (directly or indirectly). Fallback to default if
|
||||
@@ -72,8 +76,7 @@ static bool is_listed (const char *cfgin, const char *tty, bool def)
|
||||
*/
|
||||
|
||||
while (fgets (buf, sizeof (buf), fp) != NULL) {
|
||||
/* Remove optional trailing '\n'. */
|
||||
buf[strcspn (buf, "\n")] = '\0';
|
||||
*strchrnul(buf, '\n') = '\0';
|
||||
if (strcmp (buf, tty) == 0) {
|
||||
(void) fclose (fp);
|
||||
return true;
|
||||
|
||||
12
lib/getdef.c
12
lib/getdef.c
@@ -11,20 +11,22 @@
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef USE_ECONF
|
||||
#include <libeconf.h>
|
||||
#endif
|
||||
|
||||
#include "alloc.h"
|
||||
#include "atoi/str2i.h"
|
||||
#include "defines.h"
|
||||
#include "getdef.h"
|
||||
#include "prototypes.h"
|
||||
#include "shadowlog_internal.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
|
||||
@@ -579,7 +581,7 @@ static void def_load (void)
|
||||
|
||||
*s++ = '\0';
|
||||
value = s + strspn (s, " \"\t"); /* next nonwhite */
|
||||
*(value + strcspn (value, "\"")) = '\0';
|
||||
*strchrnul(value, '"') = '\0';
|
||||
|
||||
/*
|
||||
* Store the value in def_table.
|
||||
|
||||
@@ -93,11 +93,7 @@ void endsgent (void)
|
||||
}
|
||||
|
||||
strcpy (sgrbuf, string);
|
||||
|
||||
cp = strrchr (sgrbuf, '\n');
|
||||
if (NULL != cp) {
|
||||
*cp = '\0';
|
||||
}
|
||||
*strchrnul(sgrbuf, '\n') = '\0';
|
||||
|
||||
/*
|
||||
* There should be exactly 4 colon separated fields. Find
|
||||
@@ -178,10 +174,7 @@ void endsgent (void)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
cp = strrchr (buf, '\n');
|
||||
if (NULL != cp) {
|
||||
*cp = '\0';
|
||||
}
|
||||
*strchrnul(buf, '\n') = '\0';
|
||||
return (sgetsgent (buf));
|
||||
}
|
||||
return NULL;
|
||||
|
||||
10
lib/hushed.c
10
lib/hushed.c
@@ -12,12 +12,14 @@
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
#include "getdef.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
|
||||
|
||||
@@ -70,7 +72,7 @@ bool hushed (const char *username)
|
||||
return false;
|
||||
}
|
||||
for (found = false; !found && (fgets (buf, sizeof buf, fp) == buf);) {
|
||||
buf[strcspn (buf, "\n")] = '\0';
|
||||
*strchrnul(buf, '\n') = '\0';
|
||||
found = (strcmp (buf, pw->pw_shell) == 0) ||
|
||||
(strcmp (buf, pw->pw_name) == 0);
|
||||
}
|
||||
|
||||
@@ -11,12 +11,15 @@
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
#include "port.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
|
||||
static FILE *ports;
|
||||
|
||||
@@ -149,7 +152,7 @@ again:
|
||||
* TTY devices.
|
||||
*/
|
||||
|
||||
buf[strcspn (buf, "\n")] = 0;
|
||||
*strchrnul(buf, '\n') = '\0';
|
||||
|
||||
port.pt_names = ttys;
|
||||
for (cp = buf, j = 0; j < PORT_TTY; j++) {
|
||||
|
||||
@@ -82,11 +82,7 @@ struct group *sgetgrent (const char *buf)
|
||||
}
|
||||
}
|
||||
strcpy (grpbuf, buf);
|
||||
|
||||
cp = strrchr (grpbuf, '\n');
|
||||
if (NULL != cp) {
|
||||
*cp = '\0';
|
||||
}
|
||||
*strchrnul(grpbuf, '\n') = '\0';
|
||||
|
||||
for (cp = grpbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++)
|
||||
grpfields[i] = strsep(&cp, ":");
|
||||
|
||||
@@ -53,11 +53,7 @@ sgetspent(const char *string)
|
||||
return NULL; /* fail if too long */
|
||||
}
|
||||
strcpy (spwbuf, string);
|
||||
|
||||
cp = strrchr (spwbuf, '\n');
|
||||
if (NULL != cp) {
|
||||
*cp = '\0';
|
||||
}
|
||||
*strchrnul(spwbuf, '\n') = '\0';
|
||||
|
||||
/*
|
||||
* Tokenize the string into colon separated fields. Allow up to
|
||||
|
||||
24
lib/shadow.c
24
lib/shadow.c
@@ -14,12 +14,13 @@
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "atoi/str2i.h"
|
||||
#include "defines.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
|
||||
static FILE *shadow;
|
||||
@@ -75,10 +76,7 @@ static struct spwd *my_sgetspent (const char *string)
|
||||
if (strlen (string) >= sizeof spwbuf)
|
||||
return 0;
|
||||
strcpy (spwbuf, string);
|
||||
|
||||
cp = strrchr (spwbuf, '\n');
|
||||
if (NULL != cp)
|
||||
*cp = '\0';
|
||||
*strchrnul(spwbuf, '\n') = '\0';
|
||||
|
||||
/*
|
||||
* Tokenize the string into colon separated fields. Allow up to
|
||||
@@ -87,9 +85,7 @@ static struct spwd *my_sgetspent (const char *string)
|
||||
|
||||
for (cp = spwbuf, i = 0; *cp && i < FIELDS; i++) {
|
||||
fields[i] = cp;
|
||||
while (*cp && *cp != ':')
|
||||
cp++;
|
||||
|
||||
cp = strchrnul(cp, ':');
|
||||
if (*cp)
|
||||
*cp++ = '\0';
|
||||
}
|
||||
@@ -229,8 +225,7 @@ static struct spwd *my_sgetspent (const char *string)
|
||||
|
||||
struct spwd *fgetspent (FILE * fp)
|
||||
{
|
||||
char buf[BUFSIZ];
|
||||
char *cp;
|
||||
char buf[BUFSIZ];
|
||||
|
||||
if (NULL == fp) {
|
||||
return (0);
|
||||
@@ -238,10 +233,7 @@ struct spwd *fgetspent (FILE * fp)
|
||||
|
||||
if (fgets (buf, sizeof buf, fp) != NULL)
|
||||
{
|
||||
cp = strchr (buf, '\n');
|
||||
if (NULL != cp) {
|
||||
*cp = '\0';
|
||||
}
|
||||
*strchrnul(buf, '\n') = '\0';
|
||||
return my_sgetspent (buf);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -12,9 +12,13 @@
|
||||
#ident "$Id$"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "prototypes.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "defines.h"
|
||||
#include "getdef.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
|
||||
/*
|
||||
* ttytype - set ttytype from port to terminal type mapping database
|
||||
*/
|
||||
@@ -23,7 +27,6 @@ void ttytype (const char *line)
|
||||
FILE *fp;
|
||||
char buf[BUFSIZ];
|
||||
const char *typefile;
|
||||
char *cp;
|
||||
char type[1024] = "";
|
||||
char port[1024];
|
||||
|
||||
@@ -46,10 +49,7 @@ void ttytype (const char *line)
|
||||
continue;
|
||||
}
|
||||
|
||||
cp = strchr (buf, '\n');
|
||||
if (NULL != cp) {
|
||||
*cp = '\0';
|
||||
}
|
||||
*strchrnul(buf, '\n') = '\0';
|
||||
|
||||
if ( (sscanf (buf, "%1023s %1023s", type, port) == 2)
|
||||
&& (strcmp (line, port) == 0)) {
|
||||
|
||||
3
lib/tz.c
3
lib/tz.c
@@ -42,8 +42,7 @@
|
||||
|
||||
strcpy (tzbuf, def_tz);
|
||||
} else {
|
||||
/* Remove optional trailing '\n'. */
|
||||
tzbuf[strcspn (tzbuf, "\n")] = '\0';
|
||||
*strchrnul(tzbuf, '\n') = '\0';
|
||||
}
|
||||
|
||||
if (NULL != fp) {
|
||||
|
||||
@@ -360,10 +360,7 @@ static void get_defaults (void)
|
||||
* values are used, everything else can be ignored.
|
||||
*/
|
||||
while (fgets (buf, sizeof buf, fp) == buf) {
|
||||
cp = strrchr (buf, '\n');
|
||||
if (NULL != cp) {
|
||||
*cp = '\0';
|
||||
}
|
||||
*strchrnul(buf, '\n') = '\0';
|
||||
|
||||
cp = strchr (buf, '=');
|
||||
if (NULL == cp) {
|
||||
|
||||
Reference in New Issue
Block a user