]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Simplify first_weekday under Windows
authorWolfgang Stöggl <c72578@yahoo.de>
Tue, 18 Jun 2019 08:20:55 +0000 (10:20 +0200)
committerTobias Oetiker <tobi@oetiker.ch>
Tue, 18 Jun 2019 12:44:52 +0000 (14:44 +0200)
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

src/rrd_graph.c
src/rrd_rpncalc.c

index c53dcc2e09067cc4b64be750ab5517b2c9298844..f52c386c330c6cca3441f6fa37b393f14f74dc09 100644 (file)
@@ -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
index c18eaa5c230e3d54813e28ccbf390313ea4e4f7d..d3b6b7f1dd2464ce56789fbe9709d86c741bb70d 100644 (file)
@@ -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