Skip to content

Commit

Permalink
common/printf: Define _POSIX_C_SOURCE when using Newlib libc
Browse files Browse the repository at this point in the history
Newlib's `string.h` declares `strnlen()` function only when _GNU_SOURCE,
_DEFAULT_SOURCE or _POSIX_C_SOURCE is defined. Zephyr intentionally
disables POSIX declarations by defining _ANSI_SOURCE to avoid conflicts
with Zephyr POSIX library and networking subsystem [1].

It's still possible to use `strnlen()` from Newlib, we just need to
define _POSIX_C_SOURCE to 200809.

[1] zephyrproject-rtos/zephyr#52739

BUG=b:299924239
TEST=zmake build bloonchipper

Change-Id: I8cd966cd0097dfc5bf72fb9db6db6e20d96f6dee
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4973835
Commit-Queue: Patryk Duda <[email protected]>
Code-Coverage: Zoss <[email protected]>
Tested-by: Patryk Duda <[email protected]>
Reviewed-by: Sung-Chi Li <[email protected]>
  • Loading branch information
duda-patryk authored and Chromeos LUCI committed Oct 25, 2023
1 parent 26b040b commit 1d859c5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions common/printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@

/* Printf-like functionality for Chrome EC */

/*
* Define _POSIX_C_SOURCE to 200809 to unlock strnlen() when using Newlib
* libc. Newlib's CMakeLists.txt file intentionally disables POSIX definitions
* from Newlib to avoid conflicts with Zephyr POSIX library and networking
* subsystem.
*
* Refer to the Zephyr's Github issue #52739 for more details.
*/
#ifdef CONFIG_NEWLIB_LIBC
#define _POSIX_C_SOURCE 200809
#endif /* CONFIG_NEWLIB_LIBC */

#include "builtin/assert.h"
#include "console.h"
#include "printf.h"
Expand Down

0 comments on commit 1d859c5

Please sign in to comment.