Implemented the following: - `asctime_r()` - `asctime()` - `localtime()` - `localtime_r()` - `ctime()` - `ctime_r()` Specifically: - the implementation of `localtime()` & `localtime_r()` simply wraps around the gmtime() & gmtime_r() functions, the results are always expressed as UTC. - `ctime()` is equivalent to `asctime(localtime(clock))`, it inherits the limitation of `localtime()` as well, which only supports UTC results currently. Added tests for these newly implemented functions. Signed-off-by: Yong Cong Sin <ycsin@meta.com> Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
27 lines
520 B
C
27 lines
520 B
C
/*
|
|
* Copyright (c) 2024 Meta Platforms
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <time.h>
|
|
|
|
/**
|
|
* `ctime()` is equivalent to `asctime(localtime(clock))`
|
|
* See: https://pubs.opengroup.org/onlinepubs/009695399/functions/ctime.html
|
|
*/
|
|
|
|
char *ctime(const time_t *clock)
|
|
{
|
|
return asctime(localtime(clock));
|
|
}
|
|
|
|
#if defined(CONFIG_COMMON_LIBC_CTIME_R)
|
|
char *ctime_r(const time_t *clock, char *buf)
|
|
{
|
|
struct tm tmp;
|
|
|
|
return asctime_r(localtime_r(clock, &tmp), buf);
|
|
}
|
|
#endif /* CONFIG_COMMON_LIBC_CTIME_R */
|