2007-11-24 01:39:57 +05:30
|
|
|
/*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-FileCopyrightText: 2007 - 2009, Nicolas François
|
2007-11-24 01:39:57 +05:30
|
|
|
*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2007-11-24 01:39:57 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2008-04-17 03:33:43 +05:30
|
|
|
#ident "$Id$"
|
2007-11-24 01:39:57 +05:30
|
|
|
|
2009-04-11 04:04:17 +05:30
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
2007-11-24 01:39:57 +05:30
|
|
|
#include "prototypes.h"
|
|
|
|
|
2009-04-15 23:20:17 +05:30
|
|
|
/*
|
|
|
|
* 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 15:27:03 +05:30
|
|
|
int getlong (const char *numstr, /*@out@*/long int *result)
|
2007-11-24 01:39:57 +05:30
|
|
|
{
|
|
|
|
long val;
|
|
|
|
char *endptr;
|
|
|
|
|
2008-06-15 02:32:52 +05:30
|
|
|
errno = 0;
|
2009-04-15 23:20:17 +05:30
|
|
|
val = strtol (numstr, &endptr, 0);
|
2009-04-25 04:57:12 +05:30
|
|
|
if (('\0' == *numstr) || ('\0' != *endptr) || (ERANGE == errno)) {
|
2007-11-24 01:39:57 +05:30
|
|
|
return 0;
|
2008-05-26 04:55:33 +05:30
|
|
|
}
|
2007-11-24 01:39:57 +05:30
|
|
|
|
|
|
|
*result = val;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|