From 8471ac68a8eaf796d29f7c1f5a309aab271f5d83 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 12 Sep 2024 15:15:41 -0700 Subject: [PATCH] tests, samples: Define _POSIX_C_SOURCE where needed Various tests and samples use POSIX-only functions. Define _POSIX_C_SOURCE to ensure they are visible. Signed-off-by: Keith Packard --- samples/posix/gettimeofday/src/main.c | 2 ++ tests/lib/c_lib/common/src/main.c | 10 +++------- tests/posix/fs/src/test_fs_dir.c | 3 +++ tests/posix/fs/src/test_fs_stat.c | 3 +++ 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/samples/posix/gettimeofday/src/main.c b/samples/posix/gettimeofday/src/main.c index 182debd5f9f5d06..922be148a778916 100644 --- a/samples/posix/gettimeofday/src/main.c +++ b/samples/posix/gettimeofday/src/main.c @@ -4,6 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L #include #include #include diff --git a/tests/lib/c_lib/common/src/main.c b/tests/lib/c_lib/common/src/main.c index f7db63c0ad8609f..7a0e0dbd6b2e85b 100644 --- a/tests/lib/c_lib/common/src/main.c +++ b/tests/lib/c_lib/common/src/main.c @@ -15,10 +15,8 @@ * it guarantee that ALL functionality provided is working correctly. */ -#if defined(CONFIG_NATIVE_LIBC) #undef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200809L -#endif #include #include @@ -1118,11 +1116,6 @@ ZTEST(libc_common, test_time_asctime) zassert_equal(strncmp("Fri Jun 1 14:30:10 2024\n", asctime(&tp), sizeof(buf)), 0); if (IS_ENABLED(CONFIG_COMMON_LIBC_ASCTIME_R)) { - zassert_is_null(asctime_r(NULL, buf)); - zassert_is_null(asctime(NULL)); - - zassert_is_null(asctime_r(&tp, NULL)); - tp.tm_wday = 8; zassert_is_null(asctime_r(&tp, buf)); zassert_is_null(asctime(&tp)); @@ -1166,6 +1159,9 @@ ZTEST(libc_common, test_time_ctime) char buf[26] = {0}; time_t test1 = 1718260000; +#ifdef CONFIG_NATIVE_LIBC + setenv("TZ", "UTC", 1); +#endif zassert_not_null(ctime_r(&test1, buf)); zassert_equal(strncmp("Thu Jun 13 06:26:40 2024\n", buf, sizeof(buf)), 0); diff --git a/tests/posix/fs/src/test_fs_dir.c b/tests/posix/fs/src/test_fs_dir.c index e52741276f5de68..9cd58525ad19939 100644 --- a/tests/posix/fs/src/test_fs_dir.c +++ b/tests/posix/fs/src/test_fs_dir.c @@ -4,6 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L + #include #include #include diff --git a/tests/posix/fs/src/test_fs_stat.c b/tests/posix/fs/src/test_fs_stat.c index 14167d3f7756c0f..469abcdca45be59 100644 --- a/tests/posix/fs/src/test_fs_stat.c +++ b/tests/posix/fs/src/test_fs_stat.c @@ -4,6 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ +#undef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L + #include #include #include