lib/, src/: get_gid(): Use the usual -1 as an error code
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Serge Hallyn
parent
ea253cb275
commit
470baeabbd
@@ -4,6 +4,7 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#ident "$Id$"
|
||||
@@ -11,7 +12,9 @@
|
||||
#include "prototypes.h"
|
||||
#include "defines.h"
|
||||
|
||||
int get_gid (const char *gidstr, gid_t *gid)
|
||||
|
||||
int
|
||||
get_gid(const char *gidstr, gid_t *gid)
|
||||
{
|
||||
long long val;
|
||||
char *endptr;
|
||||
@@ -22,10 +25,10 @@ int get_gid (const char *gidstr, gid_t *gid)
|
||||
|| ('\0' != *endptr)
|
||||
|| (0 != errno)
|
||||
|| (/*@+longintegral@*/val != (gid_t)val)/*@=longintegral@*/) {
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*gid = val;
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ struct group *sgetgrent (const char *buf)
|
||||
}
|
||||
grent.gr_name = grpfields[0];
|
||||
grent.gr_passwd = grpfields[1];
|
||||
if (get_gid (grpfields[2], &grent.gr_gid) == 0) {
|
||||
if (get_gid(grpfields[2], &grent.gr_gid) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
grent.gr_mem = list (grpfields[3]);
|
||||
|
||||
@@ -97,7 +97,7 @@ struct passwd *sgetpwent (const char *buf)
|
||||
if (get_uid (fields[2], &pwent.pw_uid) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (get_gid (fields[3], &pwent.pw_gid) == 0) {
|
||||
if (get_gid(fields[3], &pwent.pw_gid) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
pwent.pw_gecos = fields[4];
|
||||
|
||||
@@ -403,7 +403,7 @@ static void process_flags (int argc, char **argv)
|
||||
break;
|
||||
case 'g':
|
||||
gflg = true;
|
||||
if ( (get_gid (optarg, &group_id) == 0)
|
||||
if ( (get_gid(optarg, &group_id) == -1)
|
||||
|| (group_id == (gid_t)-1)) {
|
||||
fprintf (stderr,
|
||||
_("%s: invalid group ID '%s'\n"),
|
||||
|
||||
@@ -414,7 +414,7 @@ static void process_flags (int argc, char **argv)
|
||||
break;
|
||||
case 'g':
|
||||
gflg = true;
|
||||
if ( (get_gid (optarg, &group_newid) == 0)
|
||||
if ( (get_gid(optarg, &group_newid) == -1)
|
||||
|| (group_newid == (gid_t)-1)) {
|
||||
fprintf (stderr,
|
||||
_("%s: invalid group ID '%s'\n"),
|
||||
|
||||
@@ -239,7 +239,7 @@ static int add_group (const char *name, const char *gid, gid_t *ngid, uid_t uid)
|
||||
* new group, or an existing group.
|
||||
*/
|
||||
|
||||
if (get_gid (gid, &grent.gr_gid) == 0) {
|
||||
if (get_gid(gid, &grent.gr_gid) == -1) {
|
||||
fprintf (stderr,
|
||||
_("%s: invalid group ID '%s'\n"),
|
||||
Prog, gid);
|
||||
|
||||
Reference in New Issue
Block a user