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