From 79954a1b07c6fc8ed4cf9d48c6383521b184c818 Mon Sep 17 00:00:00 2001 From: Yang Tse Date: Mon, 26 Nov 2012 16:23:02 +0100 Subject: avoid mixing of enumerated type with another type --- src/tool_getparam.c | 72 ++++++++++++++++++++++++++--------------------------- src/tool_getparam.h | 2 +- src/tool_paramhlp.c | 18 +++++++------- src/tool_paramhlp.h | 6 ++--- 4 files changed, 49 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/tool_getparam.c b/src/tool_getparam.c index 685c224de..f3d72eeed 100644 --- a/src/tool_getparam.c +++ b/src/tool_getparam.c @@ -398,9 +398,9 @@ ParameterError getparameter(char *flag, /* f or -long-flag */ GetStr(&config->egd_file, nextarg); break; case 'c': /* connect-timeout */ - rc=str2unum(&config->connecttimeout, nextarg); - if(rc) - return rc; + err = str2unum(&config->connecttimeout, nextarg); + if(err) + return err; break; case 'd': /* ciphers */ GetStr(&config->cipher_list, nextarg); @@ -545,9 +545,9 @@ ParameterError getparameter(char *flag, /* f or -long-flag */ case 's': /* --max-redirs */ /* specified max no of redirects (http(s)), this accepts -1 as a special condition */ - rc = str2num(&config->maxredirs, nextarg); - if(rc) - return rc; + err = str2num(&config->maxredirs, nextarg); + if(err) + return err; if(config->maxredirs < -1) return PARAM_BAD_NUMERIC; break; @@ -592,9 +592,9 @@ ParameterError getparameter(char *flag, /* f or -long-flag */ return PARAM_LIBCURL_DOESNT_SUPPORT; break; case 'y': /* --max-filesize */ - rc = str2offset(&config->max_filesize, nextarg); - if(rc) - return rc; + err = str2offset(&config->max_filesize, nextarg); + if(err) + return err; break; case 'z': /* --disable-eprt */ config->disable_eprt = toggle; @@ -670,19 +670,19 @@ ParameterError getparameter(char *flag, /* f or -long-flag */ config->proxybasic = toggle; break; case 'g': /* --retry */ - rc = str2unum(&config->req_retry, nextarg); - if(rc) - return rc; + err = str2unum(&config->req_retry, nextarg); + if(err) + return err; break; case 'h': /* --retry-delay */ - rc = str2unum(&config->retry_delay, nextarg); - if(rc) - return rc; + err = str2unum(&config->retry_delay, nextarg); + if(err) + return err; break; case 'i': /* --retry-max-time */ - rc = str2unum(&config->retry_maxtime, nextarg); - if(rc) - return rc; + err = str2unum(&config->retry_maxtime, nextarg); + if(err) + return err; break; case 'k': /* --proxy-negotiate */ @@ -769,9 +769,9 @@ ParameterError getparameter(char *flag, /* f or -long-flag */ config->nokeepalive = (!toggle)?TRUE:FALSE; break; case '3': /* --keepalive-time */ - rc = str2unum(&config->alivetime, nextarg); - if(rc) - return rc; + err = str2unum(&config->alivetime, nextarg); + if(err) + return err; break; case '4': /* --post302 */ config->post302 = toggle; @@ -797,9 +797,9 @@ ParameterError getparameter(char *flag, /* f or -long-flag */ config->proxyver = CURLPROXY_HTTP_1_0; break; case '9': /* --tftp-blksize */ - rc = str2unum(&config->tftp_blksize, nextarg); - if(rc) - return rc; + err = str2unum(&config->tftp_blksize, nextarg); + if(err) + return err; break; case 'A': /* --mail-from */ GetStr(&config->mail_from, nextarg); @@ -924,9 +924,9 @@ ParameterError getparameter(char *flag, /* f or -long-flag */ case 'C': /* This makes us continue an ftp transfer at given position */ if(!curlx_strequal(nextarg, "-")) { - rc = str2offset(&config->resume_from, nextarg); - if(rc) - return rc; + err = str2offset(&config->resume_from, nextarg); + if(err) + return err; config->resume_from_current = FALSE; } else { @@ -1317,9 +1317,9 @@ ParameterError getparameter(char *flag, /* f or -long-flag */ break; case 'm': /* specified max time */ - rc = str2unum(&config->timeout, nextarg); - if(rc) - return rc; + err = str2unum(&config->timeout, nextarg); + if(err) + return err; break; case 'M': /* M for manual, huge help */ if(toggle) { /* --no-manual shows no manual... */ @@ -1633,17 +1633,17 @@ ParameterError getparameter(char *flag, /* f or -long-flag */ break; case 'y': /* low speed time */ - rc = str2unum(&config->low_speed_time, nextarg); - if(rc) - return rc; + err = str2unum(&config->low_speed_time, nextarg); + if(err) + return err; if(!config->low_speed_limit) config->low_speed_limit = 1; break; case 'Y': /* low speed limit */ - rc = str2unum(&config->low_speed_limit, nextarg); - if(rc) - return rc; + err = str2unum(&config->low_speed_limit, nextarg); + if(err) + return err; if(!config->low_speed_time) config->low_speed_time = 30; break; diff --git a/src/tool_getparam.h b/src/tool_getparam.h index 49cc684c9..38f0674f4 100644 --- a/src/tool_getparam.h +++ b/src/tool_getparam.h @@ -24,7 +24,7 @@ #include "tool_setup.h" typedef enum { - PARAM_OK, + PARAM_OK = 0, PARAM_OPTION_AMBIGUOUS, PARAM_OPTION_UNKNOWN, PARAM_REQUIRES_PARAMETER, diff --git a/src/tool_paramhlp.c b/src/tool_paramhlp.c index 85912a2ef..5d6f8bbc5 100644 --- a/src/tool_paramhlp.c +++ b/src/tool_paramhlp.c @@ -146,15 +146,15 @@ void cleanarg(char *str) } /* - * Parse the string and write the long in the given address. Return non-zero - * on failure, zero on success. + * Parse the string and write the long in the given address. Return PARAM_OK + * on success, otherwise a parameter specific error enum. * * Since this function gets called with the 'nextarg' pointer from within the * getparameter a lot, we must check it for NULL before accessing the str * data. */ -int str2num(long *val, const char *str) +ParameterError str2num(long *val, const char *str) { if(str) { char *endptr; @@ -168,15 +168,15 @@ int str2num(long *val, const char *str) } /* - * Parse the string and write the long in the given address. Return non-zero - * on failure, zero on success. ONLY ACCEPTS POSITIVE NUMBERS! + * Parse the string and write the long in the given address. Return PARAM_OK + * on success, otherwise a parameter error enum. ONLY ACCEPTS POSITIVE NUMBERS! * * Since this function gets called with the 'nextarg' pointer from within the * getparameter a lot, we must check it for NULL before accessing the str * data. */ -int str2unum(long *val, const char *str) +ParameterError str2unum(long *val, const char *str) { if(str[0]=='-') return PARAM_NEGATIVE_NUMERIC; /* badness */ @@ -295,9 +295,9 @@ long proto2num(struct Configurable *config, long *val, const char *str) * * @param val the offset to populate * @param str the buffer containing the offset - * @return zero if successful, non-zero if failure. + * @return PARAM_OK if successful, a parameter specific error enum if failure. */ -int str2offset(curl_off_t *val, const char *str) +ParameterError str2offset(curl_off_t *val, const char *str) { char *endptr; if(str[0] == '-') @@ -314,7 +314,7 @@ int str2offset(curl_off_t *val, const char *str) return PARAM_BAD_NUMERIC; #endif if((endptr != str) && (endptr == str + strlen(str))) - return 0; /* Ok */ + return PARAM_OK; return PARAM_BAD_NUMERIC; } diff --git a/src/tool_paramhlp.h b/src/tool_paramhlp.h index 50c693efd..de1604e90 100644 --- a/src/tool_paramhlp.h +++ b/src/tool_paramhlp.h @@ -31,12 +31,12 @@ ParameterError file2memory(char **bufp, size_t *size, FILE *file); void cleanarg(char *str); -int str2num(long *val, const char *str); -int str2unum(long *val, const char *str); /* for unsigned input numbers */ +ParameterError str2num(long *val, const char *str); +ParameterError str2unum(long *val, const char *str); long proto2num(struct Configurable *config, long *val, const char *str); -int str2offset(curl_off_t *val, const char *str); +ParameterError str2offset(curl_off_t *val, const char *str); ParameterError checkpasswd(const char *kind, char **userpwd); -- cgit v1.2.1