zephyr/lib/libc/common/source/time/ctime.c
Keith Packard 7f412924d3 libc/common: Define _POSIX_C_SOURCE to gain access to POSIX functions
ctime.c and localtime_r_utc.c may use POSIX-only functions; to ensure those
are visible from a POSIX-conforming C library, define _POSIX_C_SOURCE in
these source files.

Signed-off-by: Keith Packard <keithp@keithp.com>
2024-09-16 20:17:35 +02:00

29 lines
575 B
C

/*
* Copyright (c) 2024 Meta Platforms
*
* SPDX-License-Identifier: Apache-2.0
*/
#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#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 */