libv4lconvert: replace strndupa with more portable strndup
authorGregor Jasny <gjasny@googlemail.com>
Thu, 2 Feb 2012 19:25:07 +0000 (20:25 +0100)
committerGregor Jasny <gjasny@googlemail.com>
Sun, 5 Feb 2012 16:00:42 +0000 (17:00 +0100)
Signed-off-by: Gregor Jasny <gjasny@googlemail.com>
lib/libv4lconvert/control/libv4lcontrol.c

index 86db9e1..4e55098 100644 (file)
@@ -432,6 +432,7 @@ static int find_dmi_string(const char **table_entries, const char *dmi_value)
        const char **entry_ptr;
        char *trimmed_dmi;
        size_t n;
+       int found = 0;
 
        if (!start) return 0;
 
@@ -439,16 +440,19 @@ static int find_dmi_string(const char **table_entries, const char *dmi_value)
        while (isspace(*start)) start++;
        n = strlen(start);
        while (n > 0 && isspace(start[n-1])) --n;
-       trimmed_dmi = strndupa(start, n);
+       trimmed_dmi = strndup(start, n);
 
        /* find trimmed value */
        for (entry_ptr = table_entries; *entry_ptr;  entry_ptr++) {
-               const int found = fnmatch(*entry_ptr, trimmed_dmi, 0) == 0;
+               found = fnmatch(*entry_ptr, trimmed_dmi, 0) == 0;
                /* fprintf(stderr, "find_dmi_string('%s', '%s'->'%s')=%i\n", *entry_ptr, dmi_value, trimmed_dmi, found); */
                if (found)
-                       return 1;
+                       break;
        }
-       return 0;
+
+       free(trimmed_dmi);
+
+       return found;
 }
 
 /*