Rewrite slack_get_is_localtime with ifstreams
This commit is contained in:
parent
33819d2eb9
commit
b8bb1c78ae
@ -16,7 +16,9 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.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;
|
return clock_settime (CLOCK_REALTIME, &ts) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean slack_get_is_localtime () {
|
gboolean slack_get_is_localtime()
|
||||||
FILE *fh;
|
{
|
||||||
char time_str[10]; // "localtime" is longer than "UTC" and has 9 letters + \0
|
std::ifstream fh{ "/etc/hardwareclock", std::ios::in };
|
||||||
gboolean is_localtime;
|
if (!fh.is_open())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
std::array<char, 10> time_str; // "localtime" is longer than "UTC" and has 9 letters + \0
|
||||||
|
|
||||||
is_localtime = FALSE;
|
while (fh.good())
|
||||||
|
{
|
||||||
|
fh.getline(time_str.data(), time_str.size());
|
||||||
|
fh.clear(fh.rdstate() & (~std::ios_base::failbit));
|
||||||
|
|
||||||
fh = fopen ("/etc/hardwareclock", "r");
|
if (std::strncmp(time_str.data(), "localtime", time_str.size()) == 0)
|
||||||
if (fh == NULL) return FALSE;
|
{
|
||||||
while (fgets (time_str, 10, fh)) {
|
return true;
|
||||||
if (!g_strcmp0 (time_str, "localtime")) {
|
}
|
||||||
is_localtime = TRUE;
|
}
|
||||||
break;
|
return false;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose (fh);
|
|
||||||
return is_localtime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean slack_get_ntp()
|
gboolean slack_get_ntp()
|
||||||
|
Loading…
Reference in New Issue
Block a user