mirror of
https://github.com/genodelabs/genode.git
synced 2025-05-22 02:07:47 +00:00
parent
4cab202d8a
commit
ebc07949ff
@ -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 \
|
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 \
|
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_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
|
INC_DIR += $(REP_DIR)/src/lib/libc
|
||||||
|
|
||||||
|
55
repos/libports/src/lib/libc/rtc.cc
Normal file
55
repos/libports/src/lib/libc/rtc.cc
Normal 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;
|
||||||
|
}
|
@ -27,6 +27,7 @@
|
|||||||
#include <vfs/log_file_system.h>
|
#include <vfs/log_file_system.h>
|
||||||
#include <vfs/rom_file_system.h>
|
#include <vfs/rom_file_system.h>
|
||||||
#include <vfs/inline_file_system.h>
|
#include <vfs/inline_file_system.h>
|
||||||
|
#include <vfs/rtc_file_system.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
#include <errno.h>
|
#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::Log_file_system>();
|
||||||
_add_builtin_fs<Vfs::Rom_file_system>();
|
_add_builtin_fs<Vfs::Rom_file_system>();
|
||||||
_add_builtin_fs<Vfs::Inline_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", "");
|
static Config_attr stderr("stderr", "");
|
||||||
return stderr.string();
|
return stderr.string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char const *config_rtc() __attribute__((weak));
|
||||||
|
char const *config_rtc()
|
||||||
|
{
|
||||||
|
static Config_attr rtc("rtc", "");
|
||||||
|
return rtc.string();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user