#include "db_config.h"
#include <sys/types.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include "db_int.h"
Go to the source code of this file.
Functions | |
| int | __db_getlong (DB *dbp, const char *progname, char *p, long min, long max, long *storep) |
| int | __db_getulong (DB *dbp, const char *progname, char *p, u_long min, u_long max, u_long *storep) |
Variables | |
| static const char | revid [] = "$Id: db_getlong.c,v 11.18 2002/03/28 20:13:33 bostic Exp $" |
|
||||||||||||||||||||||||||||
|
Definition at line 32 of file db_getlong.c. References __os_get_errno(), __os_set_errno(), NULL, strerror(), strtol(), and val. Referenced by __db_getulong(), LIST_HEAD(), and main(). 00037 { 00038 long val; 00039 char *end; 00040 00041 __os_set_errno(0); 00042 val = strtol(p, &end, 10); 00043 if ((val == LONG_MIN || val == LONG_MAX) && 00044 __os_get_errno() == ERANGE) { 00045 if (dbp == NULL) 00046 fprintf(stderr, 00047 "%s: %s: %s\n", progname, p, strerror(ERANGE)); 00048 else 00049 dbp->err(dbp, ERANGE, "%s", p); 00050 return (1); 00051 } 00052 if (p[0] == '\0' || (end[0] != '\0' && end[0] != '\n')) { 00053 if (dbp == NULL) 00054 fprintf(stderr, 00055 "%s: %s: Invalid numeric argument\n", progname, p); 00056 else 00057 dbp->errx(dbp, "%s: Invalid numeric argument", p); 00058 return (1); 00059 } 00060 if (val < min) { 00061 if (dbp == NULL) 00062 fprintf(stderr, 00063 "%s: %s: Less than minimum value (%ld)\n", 00064 progname, p, min); 00065 else 00066 dbp->errx(dbp, 00067 "%s: Less than minimum value (%ld)", p, min); 00068 return (1); 00069 } 00070 if (val > max) { 00071 if (dbp == NULL) 00072 fprintf(stderr, 00073 "%s: %s: Greater than maximum value (%ld)\n", 00074 progname, p, max); 00075 else 00076 dbp->errx(dbp, 00077 "%s: Greater than maximum value (%ld)", p, max); 00078 return (1); 00079 } 00080 *storep = val; 00081 return (0); 00082 }
|
|
||||||||||||||||||||||||||||
|
Definition at line 92 of file db_getlong.c. References __db_getlong(), __os_get_errno(), __os_set_errno(), COMPQUIET, NULL, strerror(), strtoul(), and val. Referenced by dbt_rrecno(). 00097 { 00098 #if !defined(HAVE_STRTOUL) 00099 COMPQUIET(min, 0); 00100 00101 return (__db_getlong(dbp, progname, p, 0, max, (long *)storep)); 00102 #else 00103 u_long val; 00104 char *end; 00105 00106 __os_set_errno(0); 00107 val = strtoul(p, &end, 10); 00108 if (val == ULONG_MAX && __os_get_errno() == ERANGE) { 00109 if (dbp == NULL) 00110 fprintf(stderr, 00111 "%s: %s: %s\n", progname, p, strerror(ERANGE)); 00112 else 00113 dbp->err(dbp, ERANGE, "%s", p); 00114 return (1); 00115 } 00116 if (p[0] == '\0' || (end[0] != '\0' && end[0] != '\n')) { 00117 if (dbp == NULL) 00118 fprintf(stderr, 00119 "%s: %s: Invalid numeric argument\n", progname, p); 00120 else 00121 dbp->errx(dbp, "%s: Invalid numeric argument", p); 00122 return (1); 00123 } 00124 if (val < min) { 00125 if (dbp == NULL) 00126 fprintf(stderr, 00127 "%s: %s: Less than minimum value (%lu)\n", 00128 progname, p, min); 00129 else 00130 dbp->errx(dbp, 00131 "%s: Less than minimum value (%lu)", p, min); 00132 return (1); 00133 } 00134 00135 /* 00136 * We allow a 0 to substitute as a max value for ULONG_MAX because 00137 * 1) accepting only a 0 value is unlikely to be necessary, and 2) 00138 * we don't want callers to have to use ULONG_MAX explicitly, as it 00139 * may not exist on all platforms. 00140 */ 00141 if (max != 0 && val > max) { 00142 if (dbp == NULL) 00143 fprintf(stderr, 00144 "%s: %s: Greater than maximum value (%lu)\n", 00145 progname, p, max); 00146 else 00147 dbp->errx(dbp, 00148 "%s: Greater than maximum value (%lu)", p, max); 00149 return (1); 00150 } 00151 *storep = val; 00152 return (0); 00153 #endif /* !defined(HAVE_STRTOUL) */ 00154 }
|
|
|
Definition at line 11 of file db_getlong.c. |
1.4.3