]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/get_pid.c: get_pid(): Reimplement in terms of a2i()
authorAlejandro Colomar <alx@kernel.org>
Tue, 9 Jan 2024 15:36:08 +0000 (16:36 +0100)
committerAlejandro Colomar <alx@kernel.org>
Sat, 29 Jun 2024 18:00:18 +0000 (20:00 +0200)
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/get_pid.c

index af3f2f8ea6feb4f71b4a8ad205d58fed7ff0bf74..4e8f4ef2623e95cd6ce5ece07c98f2ba79187b27 100644 (file)
 #include <sys/stat.h>
 #include <fcntl.h>
 
+#include "atoi/a2i.h"
 #include "string/sprintf.h"
 
 
 int
 get_pid(const char *pidstr, pid_t *pid)
 {
-       char       *end;
-       long long  val;
-
-       errno = 0;
-       val = strtoll(pidstr, &end, 10);
-       if (   ('\0' == *pidstr)
-           || ('\0' != *end)
-           || (0 != errno)
-           || (val < 1)
-           || (/*@+longintegral@*/val != (pid_t)val)/*@=longintegral@*/) {
-               return -1;
-       }
-
-       *pid = val;
-       return 0;
+       return a2i(pid_t, pid, pidstr, NULL, 10, 1, type_max(pid_t));
 }
 
 /*