]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/get_gid.c: get_gid(): Reimplement in terms of a2i()
authorAlejandro Colomar <alx@kernel.org>
Tue, 9 Jan 2024 14:11:25 +0000 (15:11 +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_gid.c

index 2420137bc8b793cf4496198f7e4dd0d6da30d5a3..6975792ec777d62b7f37685d10b3b7fb22cb614e 100644 (file)
@@ -1,34 +1,21 @@
-/*
- * SPDX-FileCopyrightText: 2009       , Nicolas François
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
+// SPDX-FileCopyrightText: 2009, Nicolas François
+// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
 
 
 #include <config.h>
 
 #ident "$Id$"
 
+#include <sys/types.h>
+
 #include "prototypes.h"
-#include "defines.h"
+#include "atoi/a2i.h"
+#include "typetraits.h"
 
 
 int
 get_gid(const char *gidstr, gid_t *gid)
 {
-       char       *end;
-       long long  val;
-
-       errno = 0;
-       val = strtoll(gidstr, &end, 10);
-       if (   ('\0' == *gidstr)
-           || ('\0' != *end)
-           || (0 != errno)
-           || (/*@+longintegral@*/val != (gid_t)val)/*@=longintegral@*/) {
-               return -1;
-       }
-
-       *gid = val;
-       return 0;
+       return a2i(gid_t, gid, gidstr, NULL, 10, type_min(gid_t), type_max(gid_t));
 }
-