base: utils: Add and use strtod() helper

The strtod() function is locale-dependent, and thus ill-suited to parse
numbers coming from, for instance, YAML files. The YamlObject class uses
strtod_l() to fix that issue, but that function is not available with
all libc implementations. Correctly handling this problem is becoming
out of scope for the YamlObject class.

As a first step, add a strtod() helper function in the utils namespace
that copies the implementation from YamlObject, and use it in
YamlObject. The core issue will then be fixed in utils::strtod().

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Laurent Pinchart
2023-01-05 14:07:54 +02:00
parent 2535e31d9e
commit 0e3b8d71f5
3 changed files with 49 additions and 33 deletions
+2
View File
@@ -367,6 +367,8 @@ decltype(auto) abs_diff(const T &a, const T &b)
return a - b;
}
double strtod(const char *__restrict nptr, char **__restrict endptr);
} /* namespace utils */
#ifndef __DOXYGEN__