From 2dc81adb0f1a5469b15c62d3dacf53dfbc37c17a Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Wed, 19 Dec 2018 10:43:09 +0100 Subject: [PATCH 091/142] libply: Add ply_strtod helper Add a ply_strtod helper which always uses "." as decimal separator independent of the locale. Using this fixes e.g. HorizontalAlignment in the two-step plugin not working with some locales. Signed-off-by: Hans de Goede --- src/libply/ply-utils.c | 14 ++++++++++++++ src/libply/ply-utils.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c index c17e0c8..4ff7b1b 100644 --- a/src/libply/ply-utils.c +++ b/src/libply/ply-utils.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -1109,4 +1110,17 @@ ply_kernel_command_line_override (const char *command_line) kernel_command_line_is_set = true; } +double ply_strtod(const char *str) +{ + char *old_locale; + double ret; + + /* Ensure strtod uses '.' as decimal separator, as we use this in our cfg files. */ + old_locale = setlocale(LC_NUMERIC, "C"); + ret = strtod(str, NULL); + setlocale(LC_NUMERIC, old_locale); + + return ret; +} + /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libply/ply-utils.h b/src/libply/ply-utils.h index ae4776e..4dd9c09 100644 --- a/src/libply/ply-utils.h +++ b/src/libply/ply-utils.h @@ -132,6 +132,8 @@ const char *ply_kernel_command_line_get_string_after_prefix (const char *prefix) bool ply_kernel_cmd_line_has_argument (const char *argument); void ply_kernel_cmd_line_set (const char *cmd_line); +double ply_strtod(const char *str); + #endif #endif /* PLY_UTILS_H */ -- 2.7.4