diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2023-01-06 00:47:31 +0200 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2023-01-10 17:25:51 +0200 |
commit | aed615e1730d17a3da77ea22d5af43440cc4d873 (patch) | |
tree | 4b8e318a47b5404d143640def827a3ecb1746505 /src | |
parent | 0e3b8d71f590d93540b2e6a6500cc7739f7199e9 (diff) |
libcamera: base: utils: Support C libraries lacking locale support
Not all C libraries include support for locale objects (locale_t) and
the strto*_l() family of functions. A notable example is uClibc that can
be compiled with a hardcoded "C" locale. Compilation then fails as the
newlocale(), freelocale() and strtod_l() functions are not defined.
Fix the compilation breakage by checking for the availability of the
locale_t type, and fall back to strtod() when the type isn't available.
This may not lead to the correct result if support for locale objects
isn't available and the locale isn't hardcoded to "C", but that is such
a corner case that we will likely never encounter it.
Fixes: e8ae254970cf ("libcamera: yaml_parser: Use C locale")
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/libcamera/base/utils.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libcamera/base/utils.cpp b/src/libcamera/base/utils.cpp index 4a239427..3b73b442 100644 --- a/src/libcamera/base/utils.cpp +++ b/src/libcamera/base/utils.cpp @@ -464,6 +464,8 @@ std::string toAscii(const std::string &str) * \a b */ +#if HAVE_LOCALE_T + namespace { /* @@ -493,6 +495,8 @@ Locale cLocale("C"); } /* namespace */ +#endif /* HAVE_LOCALE_T */ + /** * \brief Convert a string to a double independently of the current locale * \param[in] nptr The string to convert @@ -506,7 +510,15 @@ Locale cLocale("C"); */ double strtod(const char *__restrict nptr, char **__restrict endptr) { +#if HAVE_LOCALE_T return strtod_l(nptr, endptr, cLocale.locale()); +#else + /* + * If the libc implementation doesn't provide locale object support, + * assume that strtod() is locale-independent. + */ + return strtod(nptr, endptr); +#endif } } /* namespace utils */ |