-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libc: common: declare strnlen() and strtok_r() in string.h
Rules A.4 and A.5 of the coding guidelines allow the POSIX strnlen() and strtok_r() functions to be used anywhere within Zephyr, including in the kernel. These are not part of ISO C and typically require _POSIX_C_SOURCE to be declared. However, in Zephyr, POSIX and the interfaces it provides, are optional, and should not be used to compile the kernel and core components of the system, which is also specified by Rules A.4 and A.5 of the coding guidelines. Declare the POSIX strnlen() function with _POSIX_C_SOURCE or with _ZEPHYR_SOURCE so that it can be used easily by any C library (including those without POSIX support or those without knowledge of _ZEPHYR_SOURCE). Signed-off-by: Christopher Friedt <cfriedt@meta.com>
- Loading branch information
Showing
3 changed files
with
35 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2024, Meta | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef ZEPHYR_LIB_LIBC_COMMON_INCLUDE_STRING_H_ | ||
#define ZEPHYR_LIB_LIBC_COMMON_INCLUDE_STRING_H_ | ||
|
||
#include <stddef.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#if _POSIX_C_SOURCE >= 200809L || defined(_ZEPHYR_SOURCE) | ||
size_t strnlen(const char *s, size_t maxlen); | ||
#endif | ||
|
||
#if _POSIX_C_SOURCE >= 200112L || defined(_ZEPHYR_SOURCE) | ||
char *strtok_r(char *str, const char *sep, char **state); | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#include_next <string.h> | ||
|
||
#endif /* ZEPHYR_LIB_LIBC_COMMON_INCLUDE_STRING_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters