2007-11-24 04:09:57 +08:00
|
|
|
/*
|
2021-12-05 23:35:27 +08:00
|
|
|
* SPDX-FileCopyrightText: 2007 - 2009, Nicolas François
|
2007-11-24 04:09:57 +08:00
|
|
|
*
|
2021-12-05 23:35:27 +08:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2007-11-24 04:09:57 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2008-04-17 06:03:43 +08:00
|
|
|
#ident "$Id$"
|
2007-11-24 04:09:57 +08:00
|
|
|
|
2009-04-11 06:34:17 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
2007-11-24 04:09:57 +08:00
|
|
|
#include "prototypes.h"
|
|
|
|
|
2009-04-16 01:50:17 +08:00
|
|
|
/*
|
|
|
|
* getlong - extract a long integer provided by the numstr string in *result
|
|
|
|
*
|
|
|
|
* It supports decimal, hexadecimal or octal representations.
|
|
|
|
*
|
|
|
|
* Returns 0 on failure, 1 on success.
|
|
|
|
*/
|
* libmisc/xgetXXbyYY.c, libmisc/myname.c, libmisc/getgr_nam_gid.c,
libmisc/salt.c, libmisc/list.c, libmisc/cleanup.c, src/login.c,
lib/getdef.h, lib/groupio.c, lib/getlong.c, lib/gshadow_.h,
lib/sgroupio.c, lib/shadowio.c, lib/pwio.c, lib/commonio.h,
lib/fputsx.c, lib/prototypes.h: Added splint annotations.
* lib/groupio.c: Avoid implicit conversion of pointers to
booleans.
* lib/groupio.c: Free allocated buffers in case of failure.
2009-04-23 17:57:03 +08:00
|
|
|
int getlong (const char *numstr, /*@out@*/long int *result)
|
2007-11-24 04:09:57 +08:00
|
|
|
{
|
|
|
|
long val;
|
|
|
|
char *endptr;
|
|
|
|
|
2008-06-15 05:02:52 +08:00
|
|
|
errno = 0;
|
2009-04-16 01:50:17 +08:00
|
|
|
val = strtol (numstr, &endptr, 0);
|
2009-04-25 07:27:12 +08:00
|
|
|
if (('\0' == *numstr) || ('\0' != *endptr) || (ERANGE == errno)) {
|
2007-11-24 04:09:57 +08:00
|
|
|
return 0;
|
2008-05-26 07:25:33 +08:00
|
|
|
}
|
2007-11-24 04:09:57 +08:00
|
|
|
|
|
|
|
*result = val;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|