mirror of
https://github.com/shadow-maint/shadow.git
synced 2026-01-26 14:03:17 +00:00
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>
This commit is contained in:
parent
dc12e87fe7
commit
27e236ca79
@ -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 \
|
||||
|
||||
12
lib/atoi/str2i.c
Normal file
12
lib/atoi/str2i.c
Normal file
@ -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);
|
||||
58
lib/atoi/str2i.h
Normal file
58
lib/atoi/str2i.h
Normal file
@ -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
|
||||
@ -23,6 +23,7 @@
|
||||
#endif
|
||||
|
||||
#include "alloc.h"
|
||||
#include "atoi/str2i.h"
|
||||
#include "getdef.h"
|
||||
#include "shadowlog_internal.h"
|
||||
#include "string/sprintf.h"
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -19,6 +19,8 @@
|
||||
#include "defines.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "atoi/str2i.h"
|
||||
|
||||
|
||||
static FILE *shadow;
|
||||
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "atoi/str2i.h"
|
||||
#include "string/sprintf.h"
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
#include <pwd.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "atoi/str2i.h"
|
||||
#include "defines.h"
|
||||
#include "memzero.h"
|
||||
#include "prototypes.h"
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
@ -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)
|
||||
|
||||
/*
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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.
|
||||
*/
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
@ -37,6 +37,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "atoi/str2i.h"
|
||||
#include "chkname.h"
|
||||
#include "defines.h"
|
||||
#include "faillog.h"
|
||||
|
||||
@ -33,6 +33,7 @@
|
||||
#include <time.h>
|
||||
|
||||
#include "alloc.h"
|
||||
#include "atoi/str2i.h"
|
||||
#include "chkname.h"
|
||||
#include "defines.h"
|
||||
#include "faillog.h"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user