Update.
[glibc.git] / db2 / clib / getlong.c
blob85f4e8c9e231f7d6b3f5f8525a3070f2894580b7
1 /*-
2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 1997
5 * Sleepycat Software. All rights reserved.
6 */
8 #include "config.h"
10 #ifndef lint
11 static const char sccsid[] = "@(#)getlong.c 10.2 (Sleepycat) 5/1/97";
12 #endif /* not lint */
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <errno.h>
16 #include <limits.h>
17 #include <stdlib.h>
18 #endif
20 #include "db.h"
21 #include "clib_ext.h"
24 * get_long --
25 * Return a long value inside of basic parameters.
27 * PUBLIC: void get_long __P((char *, long, long, long *));
29 void
30 get_long(p, min, max, storep)
31 char *p;
32 long min, max, *storep;
34 long val;
35 char *end;
37 __set_errno(0);
38 val = strtol(p, &end, 10);
39 if ((val == LONG_MIN || val == LONG_MAX) && errno == ERANGE)
40 err(1, "%s", p);
41 if (p[0] == '\0' || end[0] != '\0')
42 errx(1, "%s: Invalid numeric argument", p);
43 if (val < min)
44 errx(1, "%s: Less than minimum value (%ld)", p, min);
45 if (val > max)
46 errx(1, "%s: Greater than maximum value (%ld)", p, max);
47 *storep = val;