'endptr' is appropriate internally in strtol(3) because it's a pointer to 'end', and 'end' itself is a pointer to one-after-the-last character of the numeric string. In other words, endptr == &end However, naming the pointer whose address we pass to strtol(3)'s 'endptr' feels wrong, and causes me trouble while parsing the code; I need to double check the number of dereferences, because something feels wrong in my head. Signed-off-by: Alejandro Colomar <alx@kernel.org>
35 lines
505 B
C
35 lines
505 B
C
/*
|
|
* SPDX-FileCopyrightText: 2009 , Nicolas François
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#ident "$Id$"
|
|
|
|
#include "prototypes.h"
|
|
#include "defines.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;
|
|
}
|
|
|