2 * Copyright 2015, Axel Dörfler, axeld@pinc-software.de.
3 * Copyright 2004, Jérôme Duval, jerome.duval@free.fr.
4 * Copyright 2010, 2012, Oliver Tappe <zooey@hirschkaefer.de>
5 * Distributed under the terms of the MIT License.
9 //! Initialize real time clock, and time zone offset
12 #include "InitRealTimeClockJob.h"
17 #include <FindDirectory.h>
24 using BSupportKit::BJob
;
27 InitRealTimeClockJob::InitRealTimeClockJob()
29 BJob("init real time clock")
35 InitRealTimeClockJob::Execute()
38 status_t status
= find_directory(B_USER_SETTINGS_DIRECTORY
, &path
);
40 _SetRealTimeClockIsGMT(path
);
41 _SetTimeZoneOffset(path
);
48 InitRealTimeClockJob::_SetRealTimeClockIsGMT(BPath path
) const
50 path
.Append("RTC_time_settings");
52 status_t status
= file
.SetTo(path
.Path(), B_READ_ONLY
);
54 fprintf(stderr
, "Can't open RTC settings file\n");
59 ssize_t bytesRead
= file
.Read(buffer
, sizeof(buffer
));
61 fprintf(stderr
, "Unable to read RTC settings file\n");
64 bool isGMT
= strncmp(buffer
, "local", 5) != 0;
66 _kern_set_real_time_clock_is_gmt(isGMT
);
67 printf("RTC stores %s time.\n", isGMT
? "GMT" : "local" );
72 InitRealTimeClockJob::_SetTimeZoneOffset(BPath path
) const
74 path
.Append("Time settings");
76 status_t status
= file
.SetTo(path
.Path(), B_READ_ONLY
);
78 fprintf(stderr
, "Can't open Time settings file\n");
83 status
= settings
.Unflatten(&file
);
85 fprintf(stderr
, "Unable to parse Time settings file\n");
89 if (settings
.FindString("timezone", &timeZoneID
) != B_OK
) {
90 fprintf(stderr
, "No timezone found\n");
93 int32 timeZoneOffset
= BTimeZone(timeZoneID
.String()).OffsetFromGMT();
95 _kern_set_timezone(timeZoneOffset
, timeZoneID
.String(),
97 printf("timezone is %s, offset is %" B_PRId32
" seconds from GMT.\n",
98 timeZoneID
.String(), timeZoneOffset
);