diff options
Diffstat (limited to 'slack-timedate.cpp')
| -rw-r--r-- | slack-timedate.cpp | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/slack-timedate.cpp b/slack-timedate.cpp index 607736f..3f8b2d8 100644 --- a/slack-timedate.cpp +++ b/slack-timedate.cpp @@ -16,7 +16,9 @@ * */ +#include <cstring> #include <filesystem> +#include <fstream> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -215,24 +217,26 @@ gboolean slack_set_time(gint64 seconds_since_epoch, gboolean relative) return clock_settime (CLOCK_REALTIME, &ts) == 0; } -gboolean slack_get_is_localtime () { - FILE *fh; - char time_str[10]; // "localtime" is longer than "UTC" and has 9 letters + \0 - gboolean is_localtime; - - is_localtime = FALSE; +gboolean slack_get_is_localtime() +{ + std::ifstream fh{ "/etc/hardwareclock", std::ios::in }; + if (!fh.is_open()) + { + return false; + } + std::array<char, 10> time_str; // "localtime" is longer than "UTC" and has 9 letters + \0 - fh = fopen ("/etc/hardwareclock", "r"); - if (fh == NULL) return FALSE; - while (fgets (time_str, 10, fh)) { - if (!g_strcmp0 (time_str, "localtime")) { - is_localtime = TRUE; - break; - } - } + while (fh.good()) + { + fh.getline(time_str.data(), time_str.size()); + fh.clear(fh.rdstate() & (~std::ios_base::failbit)); - fclose (fh); - return is_localtime; + if (std::strncmp(time_str.data(), "localtime", time_str.size()) == 0) + { + return true; + } + } + return false; } gboolean slack_get_ntp() |
