From 83a543036493ecc9a75521d0357af5b710261393 Mon Sep 17 00:00:00 2001 From: szabii Date: Thu, 22 Mar 2001 18:52:45 +0000 Subject: [PATCH] strto* int/float reader git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@196 b3059339-0415-0410-9bf9-f77b7e298cf2 --- cfgparser.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/cfgparser.c b/cfgparser.c index e932931842..21ec21d3c6 100644 --- a/cfgparser.c +++ b/cfgparser.c @@ -56,9 +56,10 @@ static int init_conf(struct config *conf, int mode) static int read_option(char *opt, char *param) { int i; - int tmp_int; - float tmp_float; + long tmp_int; + double tmp_float; int ret = -1; + char *endptr; for (i = 0; i < nr_options; i++) { if (!strcasecmp(opt, config[i].name)) @@ -113,14 +114,14 @@ static int read_option(char *opt, char *param) case CONF_TYPE_INT: if (param == NULL) goto err_missing_param; - if (!isdigit(*param)) { + + tmp_int = strtol(param, &endptr, 0); + if (*endptr) { printf("parameter must be an integer:\n"); ret = ERR_OUT_OF_RANGE; goto out; } - tmp_int = atoi(param); - if (config[i].flags & CONF_MIN) if (tmp_int < config[i].min) { printf("parameter must be >= %d:\n", (int) config[i].min); @@ -141,14 +142,14 @@ static int read_option(char *opt, char *param) case CONF_TYPE_FLOAT: if (param == NULL) goto err_missing_param; - if (!isdigit(*param) && *param != '-' && *param != '.') { + + tmp_float = strtod(param, &endptr); + if (*endptr) { printf("parameter must be a floating point number:\n"); ret = ERR_MISSING_PARAM; goto out; } - tmp_float = atof(param); - if (config[i].flags & CONF_MIN) if (tmp_float < config[i].min) { printf("parameter must be >= %f:\n", config[i].min);