Skip to content

Commit 1329a09

Browse files
aescolarnashif
authored andcommitted
net: ocpp: Correct way of getting strdup prototype
Zephyr subsystems' headers should not duplicate C library prototypes (in this case strdup(), which is either ISO C23 or a POSIX extension to the C library <string.h>). Instead they should request those prototypes from the C library. By now Zephyr only requires ISO C17, but many C libraries will have strdup() and expose it also when the POSIX extensions prototypes are requested, so let's request these prototype from the C library by setting the feature test macro _POSIX_C_SOURCE to version 2008.09 which includes it. Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
1 parent 1eea6ad commit 1329a09

File tree

4 files changed

+6
-8
lines changed

4 files changed

+6
-8
lines changed

samples/net/ocpp/src/main.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#undef _POSIX_C_SOURCE
8+
#define _POSIX_C_SOURCE 200809L /* for strdup() */
79
#include <stdio.h>
810
#include <time.h>
911

@@ -24,10 +26,6 @@
2426

2527
#include "net_sample_common.h"
2628

27-
#if __POSIX_VISIBLE < 200809
28-
char *strdup(const char *);
29-
#endif
30-
3129
LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);
3230

3331
#define NO_OF_CONN 2

subsys/net/lib/ocpp/key_mgmt.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#undef _POSIX_C_SOURCE
8+
#define _POSIX_C_SOURCE 200809L /* for strdup() */
79
#include "ocpp_i.h"
810

911
#if defined(CONFIG_OCPP_PROFILE_SMART_CHARGE)

subsys/net/lib/ocpp/ocpp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
#undef _POSIX_C_SOURCE
8+
#define _POSIX_C_SOURCE 200809L /* for strdup() */
79
#include "ocpp_i.h"
810

911
#include <time.h>

subsys/net/lib/ocpp/ocpp_i.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
#include <zephyr/net/websocket.h>
1515
#include <zephyr/sys/slist.h>
1616

17-
#if __POSIX_VISIBLE < 200809
18-
char *strdup(const char *);
19-
#endif
20-
2117
/* case-insensitive */
2218
#define CISTR20 20
2319
#define CISTR25 25

0 commit comments

Comments
 (0)