lib/string/strdup/xstrdup.[ch], lib/, src/: Move xstrdup() to its own file
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Serge Hallyn
parent
2cf73c99a6
commit
29f4f03def
@@ -160,6 +160,8 @@ libshadow_la_SOURCES = \
|
||||
string/strcpy/strtcpy.h \
|
||||
string/strdup/strndupa.c \
|
||||
string/strdup/strndupa.h \
|
||||
string/strdup/xstrdup.c \
|
||||
string/strdup/xstrdup.h \
|
||||
string/strdup/xstrndup.c \
|
||||
string/strdup/xstrndup.h \
|
||||
string/strftime.c \
|
||||
|
||||
18
lib/alloc.c
18
lib/alloc.c
@@ -1,12 +1,9 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 1990 - 1994, Julianne Frances Haugh
|
||||
* SPDX-FileCopyrightText: 1996 - 1998, Marek Michałkiewicz
|
||||
* SPDX-FileCopyrightText: 2003 - 2006, Tomasz Kłoczko
|
||||
* SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
* SPDX-FileCopyrightText: 2023 , Alejandro Colomar <alx@kernel.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
/* Replacements for malloc and strdup with error checking. Too trivial
|
||||
to be worth copyrighting :-). I did that because a lot of code used
|
||||
@@ -19,8 +16,6 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
#include "alloc.h"
|
||||
|
||||
#include <errno.h>
|
||||
@@ -36,7 +31,6 @@ extern inline void *xmalloc(size_t size);
|
||||
extern inline void *xmallocarray(size_t nmemb, size_t size);
|
||||
extern inline void *mallocarray(size_t nmemb, size_t size);
|
||||
extern inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
|
||||
extern inline char *xstrdup(const char *str);
|
||||
|
||||
|
||||
void *
|
||||
|
||||
10
lib/alloc.h
10
lib/alloc.h
@@ -15,7 +15,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "defines.h"
|
||||
|
||||
|
||||
#define CALLOC(n, type) ((type *) calloc(n, sizeof(type)))
|
||||
@@ -47,8 +46,6 @@ ATTR_MALLOC(free)
|
||||
inline void *mallocarray(size_t nmemb, size_t size);
|
||||
ATTR_MALLOC(free)
|
||||
inline void *reallocarrayf(void *p, size_t nmemb, size_t size);
|
||||
ATTR_MALLOC(free)
|
||||
inline char *xstrdup(const char *str);
|
||||
|
||||
ATTR_MALLOC(free)
|
||||
void *xcalloc(size_t nmemb, size_t size);
|
||||
@@ -91,11 +88,4 @@ reallocarrayf(void *p, size_t nmemb, size_t size)
|
||||
}
|
||||
|
||||
|
||||
inline char *
|
||||
xstrdup(const char *str)
|
||||
{
|
||||
return strcpy(XMALLOC(strlen(str) + 1, char), str);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
#include "alloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
/*
|
||||
* add_list - add a member to a list of group members
|
||||
*
|
||||
|
||||
@@ -13,10 +13,12 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "defines.h"
|
||||
#include "getdef.h"
|
||||
#include "prototypes.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
/*
|
||||
* motd -- output the /etc/motd file
|
||||
*
|
||||
|
||||
@@ -15,13 +15,14 @@
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "attr.h"
|
||||
#include "memzero.h"
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include "getdef.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
#if WITH_LIBBSD == 0
|
||||
#include "freezero.h"
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
#include <pwd.h>
|
||||
#include "getdef.h"
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
#ifndef USE_PAM
|
||||
|
||||
14
lib/string/strdup/xstrdup.c
Normal file
14
lib/string/strdup/xstrdup.c
Normal file
@@ -0,0 +1,14 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
extern inline char *xstrdup(const char *str);
|
||||
32
lib/string/strdup/xstrdup.h
Normal file
32
lib/string/strdup/xstrdup.h
Normal file
@@ -0,0 +1,32 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRDUP_XSTRDUP_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRDUP_XSTRDUP_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_MALLOC(free)
|
||||
inline char *xstrdup(const char *str);
|
||||
|
||||
|
||||
inline char *
|
||||
xstrdup(const char *str)
|
||||
{
|
||||
return strcpy(XMALLOC(strlen(str) + 1, char), str);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "sizeof.h"
|
||||
#include "string/strcpy/strncpy.h"
|
||||
#include "string/strcpy/strtcpy.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
#include "string/strdup/xstrndup.h"
|
||||
|
||||
#ident "$Id$"
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
#endif /* ACCT_TOOLS_SETUID */
|
||||
#include <pwd.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "atoi/str2i.h"
|
||||
#include "defines.h"
|
||||
#include "memzero.h"
|
||||
@@ -36,6 +35,7 @@
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
#include "string/strcpy/strtcpy.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
#include "string/strftime.h"
|
||||
#include "time/day_to_str.h"
|
||||
/*@-exitarg@*/
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "defines.h"
|
||||
#include "getdef.h"
|
||||
#include "nscd.h"
|
||||
@@ -34,6 +33,7 @@
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
#include "string/strcpy/strtcpy.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "defines.h"
|
||||
#include "getdef.h"
|
||||
#include "nscd.h"
|
||||
@@ -32,6 +31,7 @@
|
||||
#include "exitcodes.h"
|
||||
#include "shadowlog.h"
|
||||
#include "string/strcpy/strtcpy.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
#ifndef SHELLS_FILE
|
||||
#define SHELLS_FILE "/etc/shells"
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
#include "string/strcpy/strtcpy.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include "sgroupio.h"
|
||||
#endif
|
||||
#include "shadowlog.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
/* Exit Status Values */
|
||||
/*@-exitarg@*/
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf/stpeprintf.h"
|
||||
#include "string/strcpy/stpecpy.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
#include "string/strcpy/strtcpy.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
#include "string/strftime.h"
|
||||
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "exitcodes.h"
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
#include "chkname.h"
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "agetpass.h"
|
||||
#include "atoi/str2i.h"
|
||||
#include "defines.h"
|
||||
@@ -35,10 +34,10 @@
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
#include "string/strcpy/strtcpy.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
#include "time/day_to_str.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* exit status values
|
||||
*/
|
||||
|
||||
1
src/su.c
1
src/su.c
@@ -62,6 +62,7 @@
|
||||
#include "string/sprintf/snprintf.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
#include "string/strcpy/strtcpy.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "agetpass.h"
|
||||
#include "alloc.h"
|
||||
#include "attr.h"
|
||||
#include "defines.h"
|
||||
#include "getdef.h"
|
||||
@@ -28,6 +27,7 @@
|
||||
/*@-exitarg@*/
|
||||
#include "exitcodes.h"
|
||||
#include "shadowlog.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf/snprintf.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
#ifndef SKEL_DIR
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#ifdef ACCT_TOOLS_SETUID
|
||||
#ifdef USE_PAM
|
||||
#include "pam_defs.h"
|
||||
@@ -53,6 +52,7 @@
|
||||
#endif /* ENABLE_SUBIDS */
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
#endif
|
||||
#include "shadowlog.h"
|
||||
#include "string/sprintf/xasprintf.h"
|
||||
#include "string/strdup/xstrdup.h"
|
||||
#include "time/day_to_str.h"
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user