Implemented asctime() and asctime_r().

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7326 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2004-04-27 00:42:05 +00:00
parent 374d175555
commit 50b3e5d4ce
2 changed files with 50 additions and 0 deletions

View File

@ -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

View File

@ -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 <time.h>
#include <stdio.h>
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
}