Make UEFI boot-platform build again
[haiku.git] / src / servers / launch / InitRealTimeClockJob.cpp
blob2739e0ffc58b68b29ab2bc393e966b3f036a0279
1 /*
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.
6 */
9 //! Initialize real time clock, and time zone offset
12 #include "InitRealTimeClockJob.h"
14 #include <stdio.h>
16 #include <File.h>
17 #include <FindDirectory.h>
18 #include <Message.h>
19 #include <TimeZone.h>
21 #include <syscalls.h>
24 using BSupportKit::BJob;
27 InitRealTimeClockJob::InitRealTimeClockJob()
29 BJob("init real time clock")
34 status_t
35 InitRealTimeClockJob::Execute()
37 BPath path;
38 status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
39 if (status == B_OK) {
40 _SetRealTimeClockIsGMT(path);
41 _SetTimeZoneOffset(path);
43 return status;
47 void
48 InitRealTimeClockJob::_SetRealTimeClockIsGMT(BPath path) const
50 path.Append("RTC_time_settings");
51 BFile file;
52 status_t status = file.SetTo(path.Path(), B_READ_ONLY);
53 if (status != B_OK) {
54 fprintf(stderr, "Can't open RTC settings file\n");
55 return;
58 char buffer[10];
59 ssize_t bytesRead = file.Read(buffer, sizeof(buffer));
60 if (bytesRead < 0) {
61 fprintf(stderr, "Unable to read RTC settings file\n");
62 return;
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" );
71 void
72 InitRealTimeClockJob::_SetTimeZoneOffset(BPath path) const
74 path.Append("Time settings");
75 BFile file;
76 status_t status = file.SetTo(path.Path(), B_READ_ONLY);
77 if (status != B_OK) {
78 fprintf(stderr, "Can't open Time settings file\n");
79 return;
82 BMessage settings;
83 status = settings.Unflatten(&file);
84 if (status != B_OK) {
85 fprintf(stderr, "Unable to parse Time settings file\n");
86 return;
88 BString timeZoneID;
89 if (settings.FindString("timezone", &timeZoneID) != B_OK) {
90 fprintf(stderr, "No timezone found\n");
91 return;
93 int32 timeZoneOffset = BTimeZone(timeZoneID.String()).OffsetFromGMT();
95 _kern_set_timezone(timeZoneOffset, timeZoneID.String(),
96 timeZoneID.Length());
97 printf("timezone is %s, offset is %" B_PRId32 " seconds from GMT.\n",
98 timeZoneID.String(), timeZoneOffset);