2014-08-20 14:48:12 +00:00
|
|
|
/*
|
|
|
|
* \brief C-library back end
|
|
|
|
* \author Josef Soentgen
|
|
|
|
* \date 2014-08-20
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2014-2017 Genode Labs GmbH
|
2014-08-20 14:48:12 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2014-08-20 14:48:12 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <base/printf.h>
|
|
|
|
#include <util/string.h>
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace Libc {
|
|
|
|
extern char const *config_rtc();
|
|
|
|
time_t read_rtc();
|
|
|
|
}
|
|
|
|
|
|
|
|
time_t Libc::read_rtc()
|
|
|
|
{
|
|
|
|
time_t rtc = 0;
|
|
|
|
|
2015-01-05 10:16:45 +00:00
|
|
|
if (!Genode::strcmp(Libc::config_rtc(), "")) {
|
2015-03-06 14:54:33 +00:00
|
|
|
PWRN("%s: rtc not configured, returning %lld", __func__, (long long)rtc);
|
2015-01-05 10:16:45 +00:00
|
|
|
return rtc;
|
|
|
|
}
|
|
|
|
|
2014-08-20 14:48:12 +00:00
|
|
|
int fd = open(Libc::config_rtc(), O_RDONLY);
|
2015-01-05 10:16:45 +00:00
|
|
|
if (fd == -1) {
|
2015-03-06 14:54:33 +00:00
|
|
|
PWRN("%s: %s not readable, returning %lld", __func__, Libc::config_rtc(), (long long)rtc);
|
2014-08-20 14:48:12 +00:00
|
|
|
return rtc;
|
2015-01-05 10:16:45 +00:00
|
|
|
}
|
2014-08-20 14:48:12 +00:00
|
|
|
|
|
|
|
char buf[32];
|
|
|
|
ssize_t n = read(fd, buf, sizeof(buf));
|
|
|
|
if (n > 0) {
|
|
|
|
buf[n - 1] = '\0';
|
|
|
|
struct tm tm;
|
|
|
|
Genode::memset(&tm, 0, sizeof(tm));
|
|
|
|
|
|
|
|
if (strptime(buf, "%Y-%m-%d %R", &tm)) {
|
|
|
|
rtc = mktime(&tm);
|
|
|
|
if (rtc == (time_t)-1)
|
|
|
|
rtc = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return rtc;
|
|
|
|
}
|