[libc][common] Match the picolibc asctime_r and ctime_r prototypes

picolibc declares the buffer as char[restrict static 26], so the pointer
form warns with -Warray-parameter and the NULL check with -Wnonnull-compare.
Other C libraries keep the pointer form.

Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
This commit is contained in:
Parthiban Nallathambi authored and Rbb666 committed 2026-11-08 14:01:29 +08:00
1 parent c63d7bc9f4
commit 0b682003ff
1 file changed
+13 -3
+13 -3
View File
@@ -26,6 +26,7 @@
* 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
* 2023-10-23 Shell add lock for _g_timerid
* 2023-11-16 Shell Fixup of nanosleep if previous call was interrupted
* 2026-11-06 Parthiban match the picolibc asctime_r/ctime_r prototypes
*/
#include "sys/time.h"
@@ -59,6 +60,15 @@
#define _WARNING_NO_RTC "Cannot find a RTC device!"
/* picolibc declares the buffer as char[restrict static __ASCTIME_SIZE], so it is non-null */
#if defined(__PICOLIBC__) && defined(__ASCTIME_SIZE)
#define _ASCTIME_BUF(b) b[__restrict_arr __min_size(__ASCTIME_SIZE)]
#define _ASCTIME_BUF_NULL(b) 0
#else
#define _ASCTIME_BUF(b) *b
#define _ASCTIME_BUF_NULL(b) ((b) == RT_NULL)
#endif
#if defined(RT_USING_SMART) && defined(RT_USING_VDSO)
#include <vdso_kernel.h>
#endif
@@ -255,9 +265,9 @@ time_t mktime(struct tm * const t)
}
RTM_EXPORT(mktime);
char* asctime_r(const struct tm *t, char *buf)
char *asctime_r(const struct tm *t, char _ASCTIME_BUF(buf))
{
if(t == RT_NULL || buf == RT_NULL)
if (t == RT_NULL || _ASCTIME_BUF_NULL(buf))
{
rt_set_errno(EFAULT);
return RT_NULL;
@@ -316,7 +326,7 @@ char *asctime(const struct tm *timeptr)
}
RTM_EXPORT(asctime);
char *ctime_r(const time_t * tim_p, char * result)
char *ctime_r(const time_t *tim_p, char _ASCTIME_BUF(result))
{
struct tm tm;
return asctime_r(localtime_r(tim_p, &tm), result);