libc: add support for Rtc_file_system

Fixes #1241.
This commit is contained in:
Josef Söntgen 2014-08-20 16:48:12 +02:00 committed by Norman Feske
parent 4cab202d8a
commit ebc07949ff
3 changed files with 65 additions and 1 deletions

View File

@ -14,7 +14,7 @@ SRC_CC = atexit.cc dummies.cc rlimit.cc sysctl.cc \
gettimeofday.cc malloc.cc progname.cc fd_alloc.cc file_operations.cc \
plugin.cc plugin_registry.cc select.cc exit.cc environ.cc nanosleep.cc \
libc_mem_alloc.cc pread_pwrite.cc readv_writev.cc poll.cc \
libc_pdbg.cc vfs_plugin.cc
libc_pdbg.cc vfs_plugin.cc rtc.cc
INC_DIR += $(REP_DIR)/src/lib/libc

View File

@ -0,0 +1,55 @@
/*
* \brief C-library back end
* \author Josef Soentgen
* \date 2014-08-20
*/
/*
* Copyright (C) 2014 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#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;
int fd = open(Libc::config_rtc(), O_RDONLY);
if (fd == -1)
return rtc;
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;
}

View File

@ -27,6 +27,7 @@
#include <vfs/log_file_system.h>
#include <vfs/rom_file_system.h>
#include <vfs/inline_file_system.h>
#include <vfs/rtc_file_system.h>
/* libc includes */
#include <errno.h>
@ -158,6 +159,7 @@ class Libc_file_system_factory : public Vfs::File_system_factory
_add_builtin_fs<Vfs::Log_file_system>();
_add_builtin_fs<Vfs::Rom_file_system>();
_add_builtin_fs<Vfs::Inline_file_system>();
_add_builtin_fs<Vfs::Rtc_file_system>();
}
};
@ -228,6 +230,13 @@ namespace Libc {
static Config_attr stderr("stderr", "");
return stderr.string();
}
char const *config_rtc() __attribute__((weak));
char const *config_rtc()
{
static Config_attr rtc("rtc", "");
return rtc.string();
}
}