]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/, po/: get[u]long(): Move functions to lib/atoi/str2i.h
authorAlejandro Colomar <alx@kernel.org>
Tue, 16 Jan 2024 20:00:42 +0000 (21:00 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 29 Mar 2024 19:29:13 +0000 (14:29 -0500)
And make them inline.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
24 files changed:
lib/Makefile.am
lib/atoi/str2i.c [new file with mode: 0644]
lib/atoi/str2i.h [new file with mode: 0644]
lib/getdef.c
lib/getlong.c [deleted file]
lib/getulong.c [deleted file]
lib/idmapping.c
lib/limits.c
lib/prototypes.h
lib/rlogin.c
lib/sgetspent.c
lib/shadow.c
lib/strtoday.c
lib/subordinateio.c
po/POTFILES.in
src/chage.c
src/chgpasswd.c
src/chpasswd.c
src/faillog.c
src/lastlog.c
src/newusers.c
src/passwd.c
src/useradd.c
src/usermod.c

index 0aa9d5ec569632bce56450a1117ec78a8483f7d7..9676c5297c2496f1a9b6f7e36660de95dfe502d1 100644 (file)
@@ -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 (file)
index 0000000..1fae5a3
--- /dev/null
@@ -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 (file)
index 0000000..6bf79fc
--- /dev/null
@@ -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
index ef2ae1f08fe895aa41e83608b14ff109d66be837..41a330fa83e8b0e7f5c11be94c41b9c174f22785 100644 (file)
@@ -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 (file)
index 4f393fe..0000000
+++ /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 (file)
index c862814..0000000
+++ /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;
-}
index 2af2c202ca238807c4c4cf1e45ea6c9565c951b5..b8f0e0102023f9cdf1efbf9f87579a7e07fd936b 100644 (file)
@@ -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;
index 37a1676c6ad166af3855261a99aa83b2363a70cc..c6c041c558f247c7788c3d41c5b6a571cdf001c2 100644 (file)
 #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
index 0838884ba4b24dbc3b0cf2497c89fc88c0d5d376..5c56e77e4eeca42109d5ad6ade8361abe10e93a8 100644 (file)
@@ -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);
index c2b899eb355a64c24ba481d9e7991a20f3c733bf..792dc9f8784f63833e89c391700e58a8a580833e 100644 (file)
 #include <stdio.h>
 #include <pwd.h>
 #include <netdb.h>
+
+#include "atoi/str2i.h"
+
+
 static struct {
        int spd_name;
        int spd_baud;
index 758258f90cad8ae0b2e2f74a2c05afcf5ef77fc8..64a9c54ad1ff3186869825750b48c3b9890e3fdd 100644 (file)
@@ -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"
index 8d2c7007d902a69d4068f7e3760e63933b9f579a..f14f493755cecae98d35b38deac51d4ac305fe82 100644 (file)
@@ -19,6 +19,8 @@
 #include "defines.h"
 #include <stdio.h>
 
+#include "atoi/str2i.h"
+
 
 static FILE *shadow;
 
index 0c7a0b012bed472ae25ebc1d7b40980a03873b8b..46766a68e6fd34349c83a1082bb97c26b731bb57 100644 (file)
 
 #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:
index b1080f822ca5a8dcc8343a28e21c6450512962cd..38b09a5ed813ea33e0252d3e57f331ce29cba8f3 100644 (file)
@@ -19,6 +19,7 @@
 #include <string.h>
 
 #include "alloc.h"
+#include "atoi/str2i.h"
 #include "string/sprintf.h"
 
 
index ce610d1ab61a7cfd862115f7a0c400304cffc249..9ff6100b74bf70ac851eeb6631c818dc3c781a80 100644 (file)
@@ -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
index 1c4a20172ad41578e1ef2874ceb19b726788211d..20a1c29642a9f500fd9549e1f724af64aacd8c39 100644 (file)
@@ -27,6 +27,7 @@
 #include <pwd.h>
 
 #include "alloc.h"
+#include "atoi/str2i.h"
 #include "defines.h"
 #include "memzero.h"
 #include "prototypes.h"
index d7ac85c4303b996ceaee45b0404ddbff0a32dc5f..61aa10fbdb213772d3fb7898a06294e79a9e82f6 100644 (file)
 #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
  */
index 8233842937b38456cfadc2297fb4c532755344f3..2e865e90d56d9a9f6e4fe5c59dfe5e5e09494d0f 100644 (file)
 #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)
 
 /*
index 611802731d4b6f0831c9b04cfc87babce21a86d5..689b1fba76551940eef0a149e2a9d18c63e7a608 100644 (file)
@@ -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);
index 74b2faea3f229a2d67acecf23aa5b46d901ad271..f5c42be466c6f3eb16f40cfd36220c545a36de88 100644 (file)
@@ -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.
  */
index bff20b4432cf043fddb3a5c0062e161ad9fefd33..4f6677713597a4366d97a68f3890066bdc0086d4 100644 (file)
@@ -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"
index d90bc659af3d770af91502a99bcb0da9648096c1..df566fccbd76c93676b74a521609de76af6bf6f3 100644 (file)
@@ -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
  */
index 15e4f160bb2f36f0ab74314d056aecfdd8e6c8cf..5f5cdfca21f14a3e1d04cbc99120315afb09fdde 100644 (file)
@@ -37,6 +37,7 @@
 #include <unistd.h>
 
 #include "alloc.h"
+#include "atoi/str2i.h"
 #include "chkname.h"
 #include "defines.h"
 #include "faillog.h"
index dff0487a7059e0ad024688c2138a35722df6e14a..c11e275e5d8ec11bfddc09a56d882fdc60405afa 100644 (file)
@@ -33,6 +33,7 @@
 #include <time.h>
 
 #include "alloc.h"
+#include "atoi/str2i.h"
 #include "chkname.h"
 #include "defines.h"
 #include "faillog.h"