mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-21 22:47:50 +00:00
parent
4689275845
commit
8186a1d7f8
@ -89,10 +89,9 @@ set config {
|
||||
install_config $config
|
||||
|
||||
set build_components { test/system_rtc test/libc_rtc }
|
||||
set boot_components { test-system_rtc test-libc_rtc }
|
||||
|
||||
build $build_components
|
||||
build_boot_image $boot_components
|
||||
build_boot_image [build_artifacts]
|
||||
|
||||
append qemu_args " -nographic "
|
||||
|
||||
|
@ -47,14 +47,14 @@ struct Libc::Rtc : Vfs::Watch_response_handler
|
||||
try {
|
||||
File_content const content(_alloc, root_dir, _rtc_path.string(),
|
||||
File_content::Limit{4096U});
|
||||
|
||||
content.bytes([&] (char const *ptr, size_t size) {
|
||||
|
||||
char buf[32] { };
|
||||
::memcpy(buf, ptr, min(sizeof(buf) - 1, size));
|
||||
|
||||
struct tm tm { };
|
||||
if (strptime(buf, "%Y-%m-%d %R", &tm)) {
|
||||
if (strptime(buf, "%Y-%m-%d %H:%M:%S", &tm)
|
||||
|| strptime(buf, "%Y-%m-%d %H:%M", &tm)) {
|
||||
_rtc_value = mktime(&tm);
|
||||
if (_rtc_value == (time_t)-1)
|
||||
_rtc_value = 0;
|
||||
|
@ -215,7 +215,8 @@ int main(int argc, char **argv)
|
||||
|
||||
ts.tv_sec = ts.tv_nsec = 0;
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
printf("sleep/gettime(CLOCK_REALTIME): %.09f\n", ts.tv_sec + ts.tv_nsec / 1000000000.0);
|
||||
printf("sleep/gettime(CLOCK_REALTIME): %.09f %s\n",
|
||||
ts.tv_sec + ts.tv_nsec / 1000000000.0, asctime(localtime(&ts.tv_sec)));
|
||||
|
||||
{
|
||||
unsigned long long buf = 0;
|
||||
|
@ -21,23 +21,18 @@ int main()
|
||||
unsigned idx = 1;
|
||||
while (1) {
|
||||
struct timespec ts;
|
||||
if (clock_gettime(0, &ts)) {
|
||||
if (clock_gettime(0, &ts))
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct tm *tm = localtime((time_t*)&ts.tv_sec);
|
||||
if (!tm) {
|
||||
if (!tm)
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Timestamp #%d: %d-%d-%d %d:%d %ds\n",
|
||||
idx++,
|
||||
1900 + tm->tm_year,
|
||||
1 + tm->tm_mon,
|
||||
tm->tm_mday,
|
||||
tm->tm_hour,
|
||||
tm->tm_min,
|
||||
tm->tm_sec);
|
||||
char time_str[32];
|
||||
if (!strftime(time_str, sizeof(time_str), "%F %T", tm))
|
||||
return -1;
|
||||
|
||||
printf("Timestamp #%d: %s\n", idx++, time_str);
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ class Vfs::Rtc_file_system : public Single_file_system
|
||||
{
|
||||
private:
|
||||
|
||||
/* "1970-01-01 00:00\n" */
|
||||
enum { TIMESTAMP_LEN = 17 };
|
||||
/* "1970-01-01 00:00:00\n" */
|
||||
enum { TIMESTAMP_LEN = 20 };
|
||||
|
||||
class Rtc_vfs_handle : public Single_vfs_handle
|
||||
{
|
||||
@ -49,7 +49,7 @@ class Vfs::Rtc_file_system : public Single_file_system
|
||||
* Read the current time from the Rtc session
|
||||
*
|
||||
* On each read the current time is queried and afterwards formated
|
||||
* as '%Y-%m-%d %H:%M\n'.
|
||||
* as '%Y-%m-%d %H:%M:%S\n' resp. '%F %T\n'.
|
||||
*/
|
||||
Read_result read(char *dst, file_size count,
|
||||
file_size &out_count) override
|
||||
@ -63,8 +63,8 @@ class Vfs::Rtc_file_system : public Single_file_system
|
||||
|
||||
char buf[TIMESTAMP_LEN+1];
|
||||
char *b = buf;
|
||||
Genode::size_t n = Genode::snprintf(buf, sizeof(buf), "%04u-%02u-%02u %02u:%02u\n",
|
||||
ts.year, ts.month, ts.day, ts.hour, ts.minute);
|
||||
Genode::size_t n = Genode::snprintf(buf, sizeof(buf), "%04u-%02u-%02u %02u:%02u:%02u\n",
|
||||
ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.second);
|
||||
n -= (size_t)seek();
|
||||
b += seek();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user