summaryrefslogtreecommitdiff
path: root/db2/clib/getlong.c
blob: 85f4e8c9e231f7d6b3f5f8525a3070f2894580b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 1996, 1997
 *	Sleepycat Software.  All rights reserved.
 */

#include "config.h"

#ifndef lint
static const char sccsid[] = "@(#)getlong.c	10.2 (Sleepycat) 5/1/97";
#endif /* not lint */

#ifndef NO_SYSTEM_INCLUDES
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#endif

#include "db.h"
#include "clib_ext.h"

/*
 * get_long --
 *	Return a long value inside of basic parameters.
 *
 * PUBLIC: void get_long __P((char *, long, long, long *));
 */
void
get_long(p, min, max, storep)
	char *p;
	long min, max, *storep;
{
	long val;
	char *end;

	__set_errno(0);
	val = strtol(p, &end, 10);
	if ((val == LONG_MIN || val == LONG_MAX) && errno == ERANGE)
		err(1, "%s", p);
	if (p[0] == '\0' || end[0] != '\0')
		errx(1, "%s: Invalid numeric argument", p);
	if (val < min)
		errx(1, "%s: Less than minimum value (%ld)", p, min);
	if (val > max)
		errx(1, "%s: Greater than maximum value (%ld)", p, max);
	*storep = val;
}