2
* See the file LICENSE for redistribution information.
4
* Copyright (c) 1996-2002
5
* Sleepycat Software. All rights reserved.
11
static const char revid[] = "$Id: db_getlong.c,v 11.18 2002/03/28 20:13:33 bostic Exp $";
14
#ifndef NO_SYSTEM_INCLUDES
15
#include <sys/types.h>
26
* Return a long value inside of basic parameters.
28
* PUBLIC: int __db_getlong
29
* PUBLIC: __P((DB *, const char *, char *, long, long, long *));
32
__db_getlong(dbp, progname, p, min, max, storep)
36
long min, max, *storep;
42
val = strtol(p, &end, 10);
43
if ((val == LONG_MIN || val == LONG_MAX) &&
44
__os_get_errno() == ERANGE) {
47
"%s: %s: %s\n", progname, p, strerror(ERANGE));
49
dbp->err(dbp, ERANGE, "%s", p);
52
if (p[0] == '\0' || (end[0] != '\0' && end[0] != '\n')) {
55
"%s: %s: Invalid numeric argument\n", progname, p);
57
dbp->errx(dbp, "%s: Invalid numeric argument", p);
63
"%s: %s: Less than minimum value (%ld)\n",
67
"%s: Less than minimum value (%ld)", p, min);
73
"%s: %s: Greater than maximum value (%ld)\n",
77
"%s: Greater than maximum value (%ld)", p, max);
86
* Return an unsigned long value inside of basic parameters.
88
* PUBLIC: int __db_getulong
89
* PUBLIC: __P((DB *, const char *, char *, u_long, u_long, u_long *));
92
__db_getulong(dbp, progname, p, min, max, storep)
96
u_long min, max, *storep;
98
#if !defined(HAVE_STRTOUL)
101
return (__db_getlong(dbp, progname, p, 0, max, (long *)storep));
107
val = strtoul(p, &end, 10);
108
if (val == ULONG_MAX && __os_get_errno() == ERANGE) {
111
"%s: %s: %s\n", progname, p, strerror(ERANGE));
113
dbp->err(dbp, ERANGE, "%s", p);
116
if (p[0] == '\0' || (end[0] != '\0' && end[0] != '\n')) {
119
"%s: %s: Invalid numeric argument\n", progname, p);
121
dbp->errx(dbp, "%s: Invalid numeric argument", p);
127
"%s: %s: Less than minimum value (%lu)\n",
131
"%s: Less than minimum value (%lu)", p, min);
136
* We allow a 0 to substitute as a max value for ULONG_MAX because
137
* 1) accepting only a 0 value is unlikely to be necessary, and 2)
138
* we don't want callers to have to use ULONG_MAX explicitly, as it
139
* may not exist on all platforms.
141
if (max != 0 && val > max) {
144
"%s: %s: Greater than maximum value (%lu)\n",
148
"%s: Greater than maximum value (%lu)", p, max);
153
#endif /* !defined(HAVE_STRTOUL) */