Skip to content

Commit b4fe9f5

Browse files
committed
posix: limits: de-duplicate limit logic
Rather than duplicating limit logic in several places, de-duplicate it and centralize definitions for posix limits in posix_limits.h . Additionally, reduce the number of bugs from 3 down to 1 where PATH_MAX would be defined outside of standard usage. Signed-off-by: Chris Friedt <[email protected]>
1 parent f5cc5d8 commit b4fe9f5

File tree

4 files changed

+17
-51
lines changed

4 files changed

+17
-51
lines changed

include/zephyr/posix/posix_limits.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
#ifndef ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_LIMITS_H_
88
#define ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_LIMITS_H_
99

10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
14+
#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__)
15+
1016
/*
1117
* clang-format and checkpatch disagree on formatting here, so rely on checkpatch and disable
1218
* clang-format since checkpatch cannot be selectively disabled.
@@ -122,4 +128,15 @@
122128

123129
/* clang-format on */
124130

131+
#else
132+
133+
/* FIXME: this should only be exposed when we define _POSIX_C_SOURCE or _XOPEN_SOURCE */
134+
#define PATH_MAX 256
135+
136+
#endif
137+
138+
#ifdef __cplusplus
139+
}
140+
#endif
141+
125142
#endif /* ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_LIMITS_H_ */

lib/libc/arcmwdt/include/limits.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,6 @@
88
#define LIB_LIBC_ARCMWDT_INCLUDE_LIMITS_H_
99

1010
#include_next <limits.h>
11-
12-
#ifdef __cplusplus
13-
extern "C" {
14-
#endif
15-
16-
#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__)
17-
1811
#include <zephyr/posix/posix_limits.h>
1912

20-
#else
21-
22-
#define PATH_MAX 256
23-
24-
#endif
25-
26-
#ifdef __cplusplus
27-
}
28-
#endif
29-
3013
#endif /* ZEPHYR_LIB_LIBC_ARMSTDC_INCLUDE_LIMITS_H_ */

lib/libc/armstdc/include/limits.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,6 @@
88
#define ZEPHYR_LIB_LIBC_ARMSTDC_INCLUDE_LIMITS_H_
99

1010
#include_next <limits.h>
11-
12-
#ifdef __cplusplus
13-
extern "C" {
14-
#endif
15-
16-
#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__)
17-
1811
#include <zephyr/posix/posix_limits.h>
1912

20-
#else
21-
22-
#define PATH_MAX 256
23-
24-
#endif
25-
26-
#ifdef __cplusplus
27-
}
28-
#endif
29-
3013
#endif /* ZEPHYR_LIB_LIBC_ARMSTDC_INCLUDE_LIMITS_H_ */

lib/libc/iar/include/limits.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,6 @@
88
#define ZEPHYR_LIB_LIBC_IAR_INCLUDE_LIMITS_H_
99

1010
#include_next <limits.h>
11-
12-
#ifdef __cplusplus
13-
extern "C" {
14-
#endif
15-
16-
#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__)
17-
1811
#include <zephyr/posix/posix_limits.h>
1912

20-
#else
21-
22-
#define PATH_MAX 256
23-
24-
#endif
25-
26-
#ifdef __cplusplus
27-
}
28-
#endif
29-
3013
#endif /* ZEPHYR_LIB_LIBC_IAR_INCLUDE_LIMITS_H_ */

0 commit comments

Comments
 (0)