From: Alejandro Colomar Date: Tue, 9 Jan 2024 15:41:24 +0000 (+0100) Subject: lib/: get_pid(): Move function to "atoi/getnum.h" X-Git-Tag: 4.17.0-rc1~215 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1557fac0a5b5dc81b8a10c973cf8f51f165f6f67;p=thirdparty%2Fshadow.git lib/: get_pid(): Move function to "atoi/getnum.h" Implement it as an inline function, and add restrict and ATTR_STRING() and ATTR_ACCESS() as appropriate. Reviewed-by: "Serge E. Hallyn" Signed-off-by: Alejandro Colomar --- diff --git a/lib/atoi/getnum.c b/lib/atoi/getnum.c index 77dd23123..29e91581c 100644 --- a/lib/atoi/getnum.c +++ b/lib/atoi/getnum.c @@ -11,3 +11,4 @@ extern inline int get_gid(const char *restrict gidstr, gid_t *restrict gid); +extern inline int get_pid(const char *restrict pidstr, pid_t *restrict pid); diff --git a/lib/atoi/getnum.h b/lib/atoi/getnum.h index c6f93b84b..f92173fe8 100644 --- a/lib/atoi/getnum.h +++ b/lib/atoi/getnum.h @@ -19,6 +19,8 @@ ATTR_STRING(1) ATTR_ACCESS(write_only, 2) inline int get_gid(const char *restrict gidstr, gid_t *restrict gid); +ATTR_STRING(1) ATTR_ACCESS(write_only, 2) +inline int get_pid(const char *restrict pidstr, pid_t *restrict pid); inline int @@ -28,4 +30,11 @@ get_gid(const char *restrict gidstr, gid_t *restrict gid) } +inline int +get_pid(const char *restrict pidstr, pid_t *restrict pid) +{ + return a2i(pid_t, pid, pidstr, NULL, 10, 1, type_max(pid_t)); +} + + #endif // include guard diff --git a/lib/commonio.c b/lib/commonio.c index 01a26c964..396feff1a 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -23,6 +23,7 @@ #include #include "alloc.h" +#include "atoi/getnum.h" #include "memzero.h" #include "nscd.h" #include "sssd.h" diff --git a/lib/get_pid.c b/lib/get_pid.c index 4e8f4ef26..80e1336c3 100644 --- a/lib/get_pid.c +++ b/lib/get_pid.c @@ -14,16 +14,10 @@ #include #include -#include "atoi/a2i.h" +#include "atoi/getnum.h" #include "string/sprintf.h" -int -get_pid(const char *pidstr, pid_t *pid) -{ - return a2i(pid_t, pid, pidstr, NULL, 10, 1, type_max(pid_t)); -} - /* * If use passed in fd:4 as an argument, then return the * value '4', the fd to use. diff --git a/lib/prototypes.h b/lib/prototypes.h index 40e76625c..e36c5dccf 100644 --- a/lib/prototypes.h +++ b/lib/prototypes.h @@ -146,7 +146,6 @@ extern int find_new_sub_uids (uid_t *range_start, unsigned long *range_count); extern /*@only@*//*@null@*/struct group *getgr_nam_gid (/*@null@*/const char *grname); /* get_pid.c */ -extern int get_pid (const char *pidstr, pid_t *pid); extern int get_pidfd_from_fd(const char *pidfdstr); extern int open_pidfd(const char *pidstr); diff --git a/lib/user_busy.c b/lib/user_busy.c index a622376a8..0c7d5cbca 100644 --- a/lib/user_busy.c +++ b/lib/user_busy.c @@ -17,6 +17,8 @@ #include #include #include + +#include "atoi/getnum.h" #include "defines.h" #include "prototypes.h" #ifdef ENABLE_SUBIDS