summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2024-01-16 21:00:42 +0100
committerSerge Hallyn <serge@hallyn.com>2024-03-29 14:29:13 -0500
commit27e236ca79b6fc2a4bedc871258d0518aa5c30f5 (patch)
treedf65a4a0ecdd53465db1bbaf5c926b9a3a439754
parentdc12e87fe78a79f7240b8b26ea4e33659f4c768c (diff)
lib/, src/, po/: get[u]long(): Move functions to lib/atoi/str2i.h
And make them inline. Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r--lib/Makefile.am4
-rw-r--r--lib/atoi/str2i.c12
-rw-r--r--lib/atoi/str2i.h58
-rw-r--r--lib/getdef.c1
-rw-r--r--lib/getlong.c36
-rw-r--r--lib/getulong.c37
-rw-r--r--lib/idmapping.c2
-rw-r--r--lib/limits.c4
-rw-r--r--lib/prototypes.h8
-rw-r--r--lib/rlogin.c4
-rw-r--r--lib/sgetspent.c1
-rw-r--r--lib/shadow.c2
-rw-r--r--lib/strtoday.c2
-rw-r--r--lib/subordinateio.c1
-rw-r--r--po/POTFILES.in1
-rw-r--r--src/chage.c1
-rw-r--r--src/chgpasswd.c3
-rw-r--r--src/chpasswd.c3
-rw-r--r--src/faillog.c2
-rw-r--r--src/lastlog.c2
-rw-r--r--src/newusers.c1
-rw-r--r--src/passwd.c2
-rw-r--r--src/useradd.c1
-rw-r--r--src/usermod.c1
24 files changed, 105 insertions, 84 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 0aa9d5ec..9676c529 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -31,6 +31,8 @@ libshadow_la_SOURCES = \
agetpass.h \
alloc.c \
alloc.h \
+ atoi/str2i.c \
+ atoi/str2i.h \
atoi/strtoi.c \
atoi/strtoi.h \
atoi/strtou_noneg.c \
@@ -74,11 +76,9 @@ libshadow_la_SOURCES = \
getdate.y \
getdef.c \
getdef.h \
- getlong.c \
getgr_nam_gid.c \
getrange.c \
gettime.c \
- getulong.c \
groupio.c \
groupmem.c \
groupio.h \
diff --git a/lib/atoi/str2i.c b/lib/atoi/str2i.c
new file mode 100644
index 00000000..1fae5a3a
--- /dev/null
+++ b/lib/atoi/str2i.c
@@ -0,0 +1,12 @@
+// SPDX-FileCopyrightText: 2007-2009, Nicolas François
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "atoi/str2i.h"
+
+
+extern inline int getlong(const char *restrict s, long *restrict n);
+extern inline int getulong(const char *restrict s, unsigned long *restrict n);
diff --git a/lib/atoi/str2i.h b/lib/atoi/str2i.h
new file mode 100644
index 00000000..6bf79fc4
--- /dev/null
+++ b/lib/atoi/str2i.h
@@ -0,0 +1,58 @@
+// SPDX-FileCopyrightText: 2007-2009, Nicolas François
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_ATOI_STR2I_H_
+#define SHADOW_INCLUDE_LIB_ATOI_STR2I_H_
+
+
+#include <config.h>
+
+#include <stdlib.h>
+#include <errno.h>
+
+#include "atoi/str2i.h"
+#include "atoi/strtou_noneg.h"
+#include "attr.h"
+
+
+ATTR_ACCESS(write_only, 2)
+inline int getlong(const char *restrict s, long *restrict n);
+ATTR_ACCESS(write_only, 2)
+inline int getulong(const char *restrict s, unsigned long *restrict n);
+
+
+inline int
+getlong(const char *restrict s, long *restrict n)
+{
+ char *endp;
+ long val;
+
+ errno = 0;
+ val = strtol(s, &endp, 0);
+ if (('\0' == *s) || ('\0' != *endp) || (0 != errno))
+ return -1;
+
+ *n = val;
+ return 0;
+}
+
+
+inline int
+getulong(const char *restrict s, unsigned long *restrict n)
+{
+ char *endp;
+ unsigned long val;
+
+ errno = 0;
+ val = strtoul_noneg(s, &endp, 0);
+ if (('\0' == *s) || ('\0' != *endp) || (0 != errno))
+ return -1;
+
+ *n = val;
+ return 0;
+}
+
+
+#endif // include guard
diff --git a/lib/getdef.c b/lib/getdef.c
index ef2ae1f0..41a330fa 100644
--- a/lib/getdef.c
+++ b/lib/getdef.c
@@ -23,6 +23,7 @@
#endif
#include "alloc.h"
+#include "atoi/str2i.h"
#include "getdef.h"
#include "shadowlog_internal.h"
#include "string/sprintf.h"
diff --git a/lib/getlong.c b/lib/getlong.c
deleted file mode 100644
index 4f393fe3..00000000
--- a/lib/getlong.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2007 - 2009, Nicolas François
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-
-#include <config.h>
-
-#ident "$Id$"
-
-#include <stdlib.h>
-#include <errno.h>
-
-#include "prototypes.h"
-
-
-/*
- * getlong - extract a long integer provided by the numstr string in *result
- *
- * It supports decimal, hexadecimal or octal representations.
- */
-int
-getlong(const char *restrict numstr, long *restrict result)
-{
- char *endptr;
- long val;
-
- errno = 0;
- val = strtol(numstr, &endptr, 0);
- if (('\0' == *numstr) || ('\0' != *endptr) || (0 != errno))
- return -1;
-
- *result = val;
- return 0;
-}
diff --git a/lib/getulong.c b/lib/getulong.c
deleted file mode 100644
index c8628145..00000000
--- a/lib/getulong.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * SPDX-FileCopyrightText: 2007 - 2009, Nicolas François
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-
-#include <config.h>
-
-#ident "$Id: getlong.c 2763 2009-04-23 09:57:03Z nekral-guest $"
-
-#include <stdlib.h>
-#include <errno.h>
-
-#include "atoi/strtou_noneg.h"
-#include "prototypes.h"
-
-
-/*
- * getulong - extract an unsigned long integer provided by the numstr string in *result
- *
- * It supports decimal, hexadecimal or octal representations.
- */
-int
-getulong(const char *restrict numstr, unsigned long *restrict result)
-{
- char *endptr;
- unsigned long val;
-
- errno = 0;
- val = strtoul_noneg(numstr, &endptr, 0);
- if (('\0' == *numstr) || ('\0' != *endptr) || (0 != errno))
- return -1;
-
- *result = val;
- return 0;
-}
diff --git a/lib/idmapping.c b/lib/idmapping.c
index 2af2c202..b8f0e010 100644
--- a/lib/idmapping.c
+++ b/lib/idmapping.c
@@ -14,6 +14,7 @@
#include <strings.h>
#include "alloc.h"
+#include "atoi/str2i.h"
#include "prototypes.h"
#include "string/stpeprintf.h"
#include "idmapping.h"
@@ -24,6 +25,7 @@
#include "shadowlog.h"
#include "sizeof.h"
+
struct map_range *get_map_ranges(int ranges, int argc, char **argv)
{
struct map_range *mappings, *mapping;
diff --git a/lib/limits.c b/lib/limits.c
index 37a1676c..c6c041c5 100644
--- a/lib/limits.c
+++ b/lib/limits.c
@@ -29,7 +29,11 @@
#include "getdef.h"
#include "shadowlog.h"
#include <sys/resource.h>
+
+#include "atoi/str2i.h"
#include "memzero.h"
+
+
#ifndef LIMITS_FILE
#define LIMITS_FILE "/etc/limits"
#endif
diff --git a/lib/prototypes.h b/lib/prototypes.h
index 0838884b..5c56e77e 100644
--- a/lib/prototypes.h
+++ b/lib/prototypes.h
@@ -149,10 +149,6 @@ extern int get_gid (const char *gidstr, gid_t *gid);
/* getgr_nam_gid.c */
extern /*@only@*//*@null@*/struct group *getgr_nam_gid (/*@null@*/const char *grname);
-/* getlong.c */
-ATTR_ACCESS(write_only, 2)
-extern int getlong(const char *restrict numstr, long *restrict result);
-
/* get_pid.c */
extern int get_pid (const char *pidstr, pid_t *pid);
extern int get_pidfd_from_fd(const char *pidfdstr);
@@ -169,10 +165,6 @@ extern time_t gettime (void);
/* get_uid.c */
extern int get_uid (const char *uidstr, uid_t *uid);
-/* getulong.c */
-ATTR_ACCESS(write_only, 2)
-extern int getulong(const char *restrict numstr, unsigned long *restrict result);
-
/* fputsx.c */
ATTR_ACCESS(write_only, 1, 2)
extern /*@null@*/char *fgetsx(/*@returned@*/char *restrict, int, FILE *restrict);
diff --git a/lib/rlogin.c b/lib/rlogin.c
index c2b899eb..792dc9f8 100644
--- a/lib/rlogin.c
+++ b/lib/rlogin.c
@@ -18,6 +18,10 @@
#include <stdio.h>
#include <pwd.h>
#include <netdb.h>
+
+#include "atoi/str2i.h"
+
+
static struct {
int spd_name;
int spd_baud;
diff --git a/lib/sgetspent.c b/lib/sgetspent.c
index 758258f9..64a9c54a 100644
--- a/lib/sgetspent.c
+++ b/lib/sgetspent.c
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <string.h>
+#include "atoi/str2i.h"
#include "prototypes.h"
#include "shadowlog_internal.h"
#include "defines.h"
diff --git a/lib/shadow.c b/lib/shadow.c
index 8d2c7007..f14f4937 100644
--- a/lib/shadow.c
+++ b/lib/shadow.c
@@ -19,6 +19,8 @@
#include "defines.h"
#include <stdio.h>
+#include "atoi/str2i.h"
+
static FILE *shadow;
diff --git a/lib/strtoday.c b/lib/strtoday.c
index 0c7a0b01..46766a68 100644
--- a/lib/strtoday.c
+++ b/lib/strtoday.c
@@ -13,9 +13,11 @@
#ident "$Id$"
+#include "atoi/str2i.h"
#include "prototypes.h"
#include "getdate.h"
+
/*
* strtoday() now uses get_date() (borrowed from GNU shellutils)
* which can handle many date formats, for example:
diff --git a/lib/subordinateio.c b/lib/subordinateio.c
index b1080f82..38b09a5e 100644
--- a/lib/subordinateio.c
+++ b/lib/subordinateio.c
@@ -19,6 +19,7 @@
#include <string.h>
#include "alloc.h"
+#include "atoi/str2i.h"
#include "string/sprintf.h"
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ce610d1a..9ff6100b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -25,7 +25,6 @@ lib/fputsx.c
lib/get_gid.c
lib/get_uid.c
lib/getdef.c
-lib/getlong.c
lib/getgr_nam_gid.c
lib/getrange.c
lib/groupio.c
diff --git a/src/chage.c b/src/chage.c
index 1c4a2017..20a1c296 100644
--- a/src/chage.c
+++ b/src/chage.c
@@ -27,6 +27,7 @@
#include <pwd.h>
#include "alloc.h"
+#include "atoi/str2i.h"
#include "defines.h"
#include "memzero.h"
#include "prototypes.h"
diff --git a/src/chgpasswd.c b/src/chgpasswd.c
index d7ac85c4..61aa10fb 100644
--- a/src/chgpasswd.c
+++ b/src/chgpasswd.c
@@ -16,11 +16,13 @@
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
+
#ifdef ACCT_TOOLS_SETUID
#ifdef USE_PAM
#include "pam_defs.h"
#endif /* USE_PAM */
#endif /* ACCT_TOOLS_SETUID */
+#include "atoi/str2i.h"
#include "defines.h"
#include "nscd.h"
#include "sssd.h"
@@ -33,6 +35,7 @@
#include "exitcodes.h"
#include "shadowlog.h"
+
/*
* Global variables
*/
diff --git a/src/chpasswd.c b/src/chpasswd.c
index 82338429..2e865e90 100644
--- a/src/chpasswd.c
+++ b/src/chpasswd.c
@@ -16,9 +16,11 @@
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
+
#ifdef USE_PAM
#include "pam_defs.h"
#endif /* USE_PAM */
+#include "atoi/str2i.h"
#include "defines.h"
#include "nscd.h"
#include "sssd.h"
@@ -30,6 +32,7 @@
#include "exitcodes.h"
#include "shadowlog.h"
+
#define IS_CRYPT_METHOD(str) ((crypt_method != NULL && strcmp(crypt_method, str) == 0) ? true : false)
/*
diff --git a/src/faillog.c b/src/faillog.c
index 61180273..689b1fba 100644
--- a/src/faillog.c
+++ b/src/faillog.c
@@ -19,6 +19,7 @@
#include <time.h>
#include <assert.h>
+#include "atoi/str2i.h"
#include "defines.h"
#include "faillog.h"
#include "memzero.h"
@@ -29,6 +30,7 @@
#include "string/strftime.h"
+
/* local function prototypes */
NORETURN static void usage (int status);
static void print_one (/*@null@*/const struct passwd *pw, bool force);
diff --git a/src/lastlog.c b/src/lastlog.c
index 74b2faea..f5c42be4 100644
--- a/src/lastlog.c
+++ b/src/lastlog.c
@@ -23,6 +23,7 @@
#include <net/if.h>
#endif
+#include "atoi/str2i.h"
#include "defines.h"
#include "prototypes.h"
#include "getdef.h"
@@ -33,6 +34,7 @@
#include "string/strftime.h"
+
/*
* Needed for MkLinux DR1/2/2.1 - J.
*/
diff --git a/src/newusers.c b/src/newusers.c
index bff20b44..4f667771 100644
--- a/src/newusers.c
+++ b/src/newusers.c
@@ -31,6 +31,7 @@
#include <string.h>
#include "alloc.h"
+#include "atoi/str2i.h"
#ifdef ACCT_TOOLS_SETUID
#ifdef USE_PAM
#include "pam_defs.h"
diff --git a/src/passwd.c b/src/passwd.c
index d90bc659..df566fcc 100644
--- a/src/passwd.c
+++ b/src/passwd.c
@@ -22,6 +22,7 @@
#include "agetpass.h"
#include "alloc.h"
+#include "atoi/str2i.h"
#include "defines.h"
#include "getdef.h"
#include "memzero.h"
@@ -36,6 +37,7 @@
#include "time/day_to_str.h"
+
/*
* exit status values
*/
diff --git a/src/useradd.c b/src/useradd.c
index 15e4f160..5f5cdfca 100644
--- a/src/useradd.c
+++ b/src/useradd.c
@@ -37,6 +37,7 @@
#include <unistd.h>
#include "alloc.h"
+#include "atoi/str2i.h"
#include "chkname.h"
#include "defines.h"
#include "faillog.h"
diff --git a/src/usermod.c b/src/usermod.c
index dff0487a..c11e275e 100644
--- a/src/usermod.c
+++ b/src/usermod.c
@@ -33,6 +33,7 @@
#include <time.h>
#include "alloc.h"
+#include "atoi/str2i.h"
#include "chkname.h"
#include "defines.h"
#include "faillog.h"