Skip to content

Commit

Permalink
tests, samples: Define _POSIX_C_SOURCE where needed
Browse files Browse the repository at this point in the history
Various tests and samples use POSIX-only functions. Define _POSIX_C_SOURCE
to ensure they are visible.

Signed-off-by: Keith Packard <[email protected]>
  • Loading branch information
keith-packard committed Sep 12, 2024
1 parent be58227 commit 8471ac6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions samples/posix/gettimeofday/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
Expand Down
10 changes: 3 additions & 7 deletions tests/lib/c_lib/common/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <zephyr/kernel.h>
#include <zephyr/sys/__assert.h>
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions tests/posix/fs/src/test_fs_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L

#include <stdio.h>
#include <fcntl.h>
#include <zephyr/posix/unistd.h>
Expand Down
3 changes: 3 additions & 0 deletions tests/posix/fs/src/test_fs_stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

#undef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L

#include <string.h>
#include <zephyr/posix/fcntl.h>
#include <zephyr/posix/unistd.h>
Expand Down

0 comments on commit 8471ac6

Please sign in to comment.