From 50b3e5d4ce30fed676347d37f4ddbf9121d07ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 27 Apr 2004 00:42:05 +0000 Subject: [PATCH] Implemented asctime() and asctime_r(). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7326 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/libroot/posix/time/Jamfile | 1 + src/kernel/libroot/posix/time/asctime.c | 49 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/kernel/libroot/posix/time/asctime.c diff --git a/src/kernel/libroot/posix/time/Jamfile b/src/kernel/libroot/posix/time/Jamfile index 1ad6a4b102..3ec06f11a6 100644 --- a/src/kernel/libroot/posix/time/Jamfile +++ b/src/kernel/libroot/posix/time/Jamfile @@ -1,6 +1,7 @@ SubDir OBOS_TOP src kernel libroot posix time ; KernelMergeObject posix_time.o : + <$(SOURCE_GRIST)>asctime.c <$(SOURCE_GRIST)>time.c : -fPIC -DPIC diff --git a/src/kernel/libroot/posix/time/asctime.c b/src/kernel/libroot/posix/time/asctime.c new file mode 100644 index 0000000000..f2eb144be9 --- /dev/null +++ b/src/kernel/libroot/posix/time/asctime.c @@ -0,0 +1,49 @@ +/* +** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + + +#include +#include + + +static char * +print_time(char *buffer, size_t bufferSize, const struct tm *tm) +{ + // ToDo: this should probably use the locale kit to get these names + + static const char weekdays[][3] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" + }; + static const char months[][3] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + }; + + snprintf(buffer, bufferSize, "%.3s %.3s%3d %02d:%02d:%02d %d\n", + weekdays[tm->tm_wday % 7], months[tm->tm_mon % 12], + tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, + 1900 + tm->tm_year); + + return buffer; +} + + +char * +asctime(const struct tm *tm) +{ + static char buffer[28]; + // is enough to hold normal dates + + return print_time(buffer, sizeof(buffer), tm); +} + + +char * +asctime_r(const struct tm *tm, char *buffer) +{ + return print_time(buffer, 26, tm); + // 26 bytes seems to be required by the standard, so we can't write more +} +