Merge branch 'master' into gfio
[fio.git] / parse.c
diff --git a/parse.c b/parse.c
index 9a6494f32db811746ba46303b5f300a83e1ddfc6..a0b18e26e85af4081fc32b982250e5e500b1d874 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -14,6 +14,7 @@
 #include "parse.h"
 #include "debug.h"
 #include "options.h"
+#include "minmax.h"
 
 static struct fio_option *__fio_options;
 
@@ -219,7 +220,7 @@ static unsigned long long get_mult_bytes(const char *str, int len, void *data,
 /*
  * Convert string into a floating number. Return 1 for success and 0 otherwise.
  */
-static int str_to_float(const char *str, double *val)
+int str_to_float(const char *str, double *val)
 {
        return (1 == sscanf(str, "%lf", val));
 }
@@ -342,6 +343,11 @@ static int opt_len(const char *str)
        return (int)(postfix - str);
 }
 
+static int str_match_len(const struct value_pair *vp, const char *str)
+{
+       return max(strlen(vp->ival), opt_len(str));
+}
+
 #define val_store(ptr, val, off, or, data)             \
        do {                                            \
                ptr = td_var((data), (off));            \
@@ -359,7 +365,7 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
        long long ull, *ullp;
        long ul1, ul2;
        double uf;
-       char **cp;
+       char **cp = NULL;
        int ret = 0, is_time = 0;
        const struct value_pair *vp;
        struct value_pair posval[PARSE_MAX_VP];
@@ -386,7 +392,7 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
                        if (!vp->ival || vp->ival[0] == '\0')
                                continue;
                        all_skipped = 0;
-                       if (!strncmp(vp->ival, ptr, opt_len(ptr))) {
+                       if (!strncmp(vp->ival, ptr, str_match_len(vp, ptr))) {
                                ret = 0;
                                if (o->roff1) {
                                        if (vp->or)
@@ -534,8 +540,6 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
                                cp = td_var(data, o->off1);
 
                        *cp = strdup(ptr);
-               } else {
-                       cp = NULL;
                }
 
                if (fn)
@@ -549,7 +553,7 @@ static int __handle_option(struct fio_option *o, const char *ptr, void *data,
                                if (!vp->ival || vp->ival[0] == '\0')
                                        continue;
                                all_skipped = 0;
-                               if (!strncmp(vp->ival, ptr, opt_len(ptr))) {
+                               if (!strncmp(vp->ival, ptr, str_match_len(vp, ptr))) {
                                        char *rest;
 
                                        ret = 0;
@@ -1090,6 +1094,9 @@ void option_init(struct fio_option *o)
                        o->maxval = UINT_MAX;
        }
        if (o->type == FIO_OPT_FLOAT_LIST) {
+#ifndef NAN
+#define NAN __builtin_nanf("")
+#endif
                o->minfp = NAN;
                o->maxfp = NAN;
        }