strto* functions happily chomp off leading whitespace, so simply
checking for str[0] can lead to false negatives. Do the full parse and
check the out value instead.
ParameterError str2unum(long *val, const char *str)
{
- if(str[0]=='-')
- return PARAM_NEGATIVE_NUMERIC; /* badness */
- return str2num(val, str);
+ ParameterError result = str2num(val, str);
+ if(result != PARAM_OK)
+ return result;
+ if(*val < 0)
+ return PARAM_NEGATIVE_NUMERIC;
+
+ return PARAM_OK;
}
/*