From: Wolfgang Stöggl Date: Tue, 18 Jun 2019 08:20:55 +0000 (+0200) Subject: Simplify first_weekday under Windows X-Git-Tag: v1.8.0~88 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c9a46d1b77a0f212a75169d9cd051e5e3bf7558b;p=thirdparty%2Frrdtool-1.x.git Simplify first_weekday under Windows Use LOCALE_IFIRSTDAYOFWEEK | LOCALE_RETURN_NUMBER. In this case, the function GetLocaleInfoEx() retrieves the value as a number instead of a string. According to: GetLocaleInfoEx function (winnls.h) | Microsoft Docs sscanf() is not required any more to convert a char array to an int --- diff --git a/src/rrd_graph.c b/src/rrd_graph.c index c53dcc2e..f52c386c 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -1569,14 +1569,15 @@ static int find_first_weekday( } first_weekday = (week_1stday + first_weekday - 1) % 7; #elif defined(_WIN32) && defined(LOCALE_NAME_USER_DEFAULT) - const char wsDay[4]; /* sscanf requires const char */ + DWORD week_1stday; - GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK, - (LPWSTR) & wsDay, 4); - sscanf(wsDay, "%d", &first_weekday); + GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, + LOCALE_IFIRSTDAYOFWEEK | LOCALE_RETURN_NUMBER, + (LPWSTR) & week_1stday, + sizeof(week_1stday) / sizeof(WCHAR)); /* 0:Monday, ..., 6:Sunday. */ /* We need 1 for Monday, 0 for Sunday. */ - first_weekday = (first_weekday + 1) % 7; + first_weekday = (week_1stday + 1) % 7; #else first_weekday = 0; #endif diff --git a/src/rrd_rpncalc.c b/src/rrd_rpncalc.c index c18eaa5c..d3b6b7f1 100644 --- a/src/rrd_rpncalc.c +++ b/src/rrd_rpncalc.c @@ -576,14 +576,15 @@ static int find_first_weekday( } first_weekday = (week_1stday + first_weekday - 1) % 7; #elif defined(_WIN32) && defined(LOCALE_NAME_USER_DEFAULT) - const char wsDay[4]; /* sscanf requires const char */ + DWORD week_1stday; - GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK, - (LPWSTR) & wsDay, 4); - sscanf(wsDay, "%d", &first_weekday); + GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, + LOCALE_IFIRSTDAYOFWEEK | LOCALE_RETURN_NUMBER, + (LPWSTR) & week_1stday, + sizeof(week_1stday) / sizeof(WCHAR)); /* 0:Monday, ..., 6:Sunday. */ /* We need 1 for Monday, 0 for Sunday. */ - first_weekday = (first_weekday + 1) % 7; + first_weekday = (week_1stday + 1) % 7; #else first_weekday = 0; #endif