Skip to content

Commit 8605f20

Browse files
committed
posix: remove zephyr posix headers from include path
This change removes the requirement to have `<zephyr/posix/...>` prefixing all standard POSIX includes in Zephyr. The main reason that it was required was due to conflicts between C library time.h, signal.h and the fact that Zephyr posix headers were being somewhat ad-hoc mixed with libc posix headers. Now, any (even partially) POSIX-conformant C libraries are expected to provide their own types, constants, and headers, and Zephyr's implementation uses those definitions. If any definitions are missing, we define them on a per-libc basis. This can also be done out-of-tree, which allows for implementors to take advantage of the `CONFIG_TC_PROVIDES_POSIX..` options. Signed-off-by: Chris Friedt <[email protected]>
1 parent f6d3f48 commit 8605f20

File tree

129 files changed

+1928
-864
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+1928
-864
lines changed

include/zephyr/posix/aio.h

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,60 @@
77
#ifndef ZEPHYR_INCLUDE_ZEPHYR_POSIX_AIO_H_
88
#define ZEPHYR_INCLUDE_ZEPHYR_POSIX_AIO_H_
99

10+
/* size_t must be defined by the libc stddef.h */
11+
#include <stddef.h>
12+
#include <stdint.h>
1013
#include <signal.h>
11-
#include <sys/types.h>
12-
#include <time.h>
1314

1415
#include <zephyr/toolchain.h>
1516

1617
#ifdef __cplusplus
1718
extern "C" {
1819
#endif
1920

21+
#if !defined(_OFF_T_DECLARED) && !defined(__off_t_defined)
22+
typedef long off_t;
23+
#define _OFF_T_DECLARED
24+
#define __off_t_defined
25+
#endif
26+
27+
#ifndef __SIZE_TYPE__
28+
#define __SIZE_TYPE__ unsigned long
29+
#endif
30+
31+
#if !defined(_SSIZE_T_DECLARED) && !defined(__ssize_t_defined)
32+
#define unsigned signed /* parasoft-suppress MISRAC2012-RULE_20_4-a MISRAC2012-RULE_20_4-b */
33+
typedef __SIZE_TYPE__ ssize_t;
34+
#undef unsigned
35+
#define _SSIZE_T_DECLARED
36+
#define __ssize_t_defined
37+
#endif
38+
39+
/* time_t must be defined by the libc time.h */
40+
#include <time.h>
41+
42+
#if __STDC_VERSION__ >= 201112L
43+
/* struct timespec must be defined in the libc time.h */
44+
#else
45+
#if !defined(_TIMESPEC_DECLARED) && !defined(__timespec_defined)
46+
struct timespec {
47+
time_t tv_sec;
48+
long tv_nsec;
49+
};
50+
#define _TIMESPEC_DECLARED
51+
#define __timespec_defined
52+
#endif
53+
#endif
54+
2055
struct aiocb {
2156
int aio_fildes;
2257
off_t aio_offset;
2358
volatile void *aio_buf;
2459
size_t aio_nbytes;
2560
int aio_reqprio;
61+
#if defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__)
2662
struct sigevent aio_sigevent;
63+
#endif /* defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) */
2764
int aio_lio_opcode;
2865
};
2966

include/zephyr/posix/dirent.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,29 @@
88
#ifndef ZEPHYR_INCLUDE_POSIX_DIRENT_H_
99
#define ZEPHYR_INCLUDE_POSIX_DIRENT_H_
1010

11-
#include <sys/dirent.h>
11+
#include <limits.h>
12+
1213
#include <zephyr/toolchain.h>
1314

1415
#ifdef __cplusplus
1516
extern "C" {
1617
#endif
1718

19+
#if !defined(NAME_MAX) && defined(_XOPEN_SOURCE)
20+
#define NAME_MAX _XOPEN_NAME_MAX
21+
#endif
22+
23+
#if !defined(NAME_MAX) && defined(_POSIX_C_SOURCE)
24+
#define NAME_MAX _POSIX_NAME_MAX
25+
#endif
26+
27+
typedef void DIR;
28+
29+
struct dirent {
30+
unsigned int d_ino;
31+
char d_name[NAME_MAX + 1];
32+
};
33+
1834
#if (_POSIX_C_SOURCE >= 200809L) || (_XOPEN_SOURCE >= 700)
1935
int alphasort(const struct dirent **d1, const struct dirent **d2);
2036
#endif

include/zephyr/posix/fnmatch.h

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,31 @@
1-
/* SPDX-License-Identifier: BSD-3-Clause */
2-
3-
/* $NetBSD: fnmatch.h,v 1.12.50.1 2011/02/08 16:18:55 bouyer Exp $ */
4-
5-
/*-
6-
* Copyright (c) 1992, 1993
7-
* The Regents of the University of California. All rights reserved.
8-
*
9-
* Redistribution and use in source and binary forms, with or without
10-
* modification, are permitted provided that the following conditions
11-
* are met:
12-
* 1. Redistributions of source code must retain the above copyright
13-
* notice, this list of conditions and the following disclaimer.
14-
* 2. Redistributions in binary form must reproduce the above copyright
15-
* notice, this list of conditions and the following disclaimer in the
16-
* documentation and/or other materials provided with the distribution.
17-
* 3. Neither the name of the University nor the names of its contributors
18-
* may be used to endorse or promote products derived from this software
19-
* without specific prior written permission.
20-
*
21-
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22-
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24-
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27-
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28-
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29-
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30-
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31-
* SUCH DAMAGE.
1+
/*
2+
* Copyright The Zephyr Project Contributors
323
*
33-
* @(#)fnmatch.h 8.1 (Berkeley) 6/2/93
4+
* SPDX-License-Identifier: Apache-2.0
345
*/
356

36-
#ifndef _FNMATCH_H_
37-
#define _FNMATCH_H_
38-
39-
#define FNM_NOMATCH 1 /* Match failed. */
40-
#define FNM_NOSYS 2 /* Function not implemented. */
41-
#define FNM_NORES 3 /* Out of resources */
42-
43-
#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
44-
#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
45-
#define FNM_PERIOD 0x04 /* Period must be matched by period. */
46-
#define FNM_CASEFOLD 0x08 /* Pattern is matched case-insensitive */
47-
#define FNM_LEADING_DIR 0x10 /* Ignore /<tail> after Imatch. */
7+
#ifndef ZEPHYR_INCLUDE_POSIX_FNMATCH_H_
8+
#define ZEPHYR_INCLUDE_POSIX_FNMATCH_H_
489

4910
#ifdef __cplusplus
5011
extern "C" {
5112
#endif
5213

53-
int fnmatch(const char *, const char *, int);
14+
#define FNM_NOMATCH 1
15+
#define FNM_NOESCAPE 0x01
16+
#define FNM_PATHNAME 0x02
17+
#define FNM_PERIOD 0x04
18+
#if defined(__GNU_SOURCE)
19+
#define FNM_LEADING_DIR 0x08
20+
#endif
21+
#define FNM_CASEFOLD 0x10
22+
#define FNM_EXTMATCH 0x20
23+
#define FNM_IGNORECASE FNM_CASEFOLD
24+
25+
int fnmatch(const char *pattern, const char *string, int flags);
5426

5527
#ifdef __cplusplus
5628
}
5729
#endif
5830

59-
#endif /* !_FNMATCH_H_ */
31+
#endif /* ZEPHYR_INCLUDE_POSIX_FNMATCH_H_ */

include/zephyr/posix/mqueue.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@
1010
#include <time.h>
1111
#include <signal.h>
1212

13-
#include <zephyr/kernel.h>
14-
#include <fcntl.h>
15-
#include <sys/stat.h>
16-
#include <posix_types.h>
17-
1813
#ifdef __cplusplus
1914
extern "C" {
2015
#endif

include/zephyr/posix/posix_features.h

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -36,130 +36,30 @@
3636
* POSIX System Interfaces
3737
*/
3838

39-
#define _POSIX_VERSION 200809L
40-
4139
#define _POSIX_CHOWN_RESTRICTED (0)
4240
#define _POSIX_NO_TRUNC (0)
4341
#define _POSIX_VDISABLE ('\0')
4442

4543
/* #define _POSIX_ADVISORY_INFO (-1L) */
4644

47-
#ifdef CONFIG_POSIX_ASYNCHRONOUS_IO
48-
#define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION
49-
#endif
50-
51-
#ifdef CONFIG_POSIX_BARRIERS
52-
#define _POSIX_BARRIERS _POSIX_VERSION
53-
#endif
54-
55-
#ifdef CONFIG_POSIX_FSYNC
56-
#define _POSIX_FSYNC _POSIX_VERSION
57-
#endif
58-
59-
#ifdef CONFIG_NET_IPV6
60-
#define _POSIX_IPV6 _POSIX_VERSION
61-
#endif
62-
6345
/* #define _POSIX_JOB_CONTROL (-1L) */
6446

65-
#ifdef CONFIG_POSIX_MAPPED_FILES
66-
#define _POSIX_MAPPED_FILES _POSIX_VERSION
67-
#endif
68-
69-
#ifdef CONFIG_POSIX_MEMLOCK
70-
#define _POSIX_MEMLOCK _POSIX_VERSION
71-
#endif
72-
73-
#ifdef CONFIG_POSIX_MEMLOCK_RANGE
74-
#define _POSIX_MEMLOCK_RANGE _POSIX_VERSION
75-
#endif
76-
77-
#ifdef CONFIG_POSIX_MEMORY_PROTECTION
78-
#define _POSIX_MEMORY_PROTECTION _POSIX_VERSION
79-
#endif
80-
81-
#ifdef CONFIG_POSIX_MESSAGE_PASSING
82-
#define _POSIX_MESSAGE_PASSING _POSIX_VERSION
83-
#endif
84-
8547
/* #define _POSIX_PRIORITIZED_IO (-1L) */
8648

87-
#ifdef CONFIG_POSIX_PRIORITY_SCHEDULING
88-
#define _POSIX_PRIORITY_SCHEDULING _POSIX_VERSION
89-
#endif
90-
91-
#ifdef CONFIG_NET_SOCKETS_PACKET
92-
#define _POSIX_RAW_SOCKETS _POSIX_VERSION
93-
#endif
94-
95-
#ifdef CONFIG_POSIX_RW_LOCKS
96-
#define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION
97-
#endif
98-
9949
/* #define _POSIX_REGEXP (-1L) */
10050
/* #define _POSIX_SAVED_IDS (-1L) */
10151

102-
#ifdef CONFIG_POSIX_SEMAPHORES
103-
#define _POSIX_SEMAPHORES _POSIX_VERSION
104-
#endif
105-
106-
#ifdef CONFIG_POSIX_SHARED_MEMORY_OBJECTS
107-
#define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION
108-
#endif
109-
11052
/* #define _POSIX_SHELL (-1L) */
11153
/* #define _POSIX_SPAWN (-1L) */
11254

113-
#ifdef CONFIG_POSIX_SPIN_LOCKS
114-
#define _POSIX_SPIN_LOCKS _POSIX_VERSION
115-
#endif
116-
11755
/* #define _POSIX_SPORADIC_SERVER (-1L) */
11856

119-
#ifdef CONFIG_POSIX_SYNCHRONIZED_IO
120-
#define _POSIX_SYNCHRONIZED_IO _POSIX_VERSION
121-
#endif
122-
123-
#ifdef CONFIG_POSIX_THREAD_ATTR_STACKADDR
124-
#define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION
125-
#endif
126-
127-
#ifdef CONFIG_POSIX_THREAD_ATTR_STACKSIZE
128-
#define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION
129-
#endif
130-
131-
#ifdef CONFIG_POSIX_THREAD_CPUTIME
132-
#define _POSIX_THREAD_CPUTIME _POSIX_VERSION
133-
#endif
134-
135-
#ifdef CONFIG_POSIX_THREAD_PRIO_INHERIT
136-
#define _POSIX_THREAD_PRIO_INHERIT _POSIX_VERSION
137-
#endif
138-
139-
#ifdef CONFIG_POSIX_THREAD_PRIO_PROTECT
140-
#define _POSIX_THREAD_PRIO_PROTECT _POSIX_VERSION
141-
#endif
142-
143-
#ifdef CONFIG_POSIX_THREAD_PRIORITY_SCHEDULING
144-
#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION
145-
#endif
146-
14757
/* #define _POSIX_THREAD_PROCESS_SHARED (-1L) */
14858
/* #define _POSIX_THREAD_ROBUST_PRIO_INHERIT (-1L) */
14959
/* #define _POSIX_THREAD_ROBUST_PRIO_PROTECT (-1L) */
15060

15161
/* #define _POSIX_THREAD_SPORADIC_SERVER (-1L) */
15262

153-
#ifdef CONFIG_POSIX_THREADS
154-
#ifndef _POSIX_THREADS
155-
#define _POSIX_THREADS _POSIX_VERSION
156-
#endif
157-
#endif
158-
159-
#ifdef CONFIG_POSIX_TIMEOUTS
160-
#define _POSIX_TIMEOUTS _POSIX_VERSION
161-
#endif
162-
16363
/* #define _POSIX_TRACE (-1L) */
16464
/* #define _POSIX_TRACE_EVENT_FILTER (-1L) */
16565
/* #define _POSIX_TRACE_INHERIT (-1L) */
@@ -185,8 +85,6 @@
18585
/*
18686
* POSIX2 Options
18787
*/
188-
/* #define _POSIX2_VERSION (-1) */
189-
#define _POSIX2_C_BIND _POSIX_VERSION
19088
/* #define _POSIX2_C_DEV (-1) */
19189
/* #define _POSIX2_CHAR_TERM (-1L) */
19290
/* #define _POSIX2_FORT_DEV (-1L) */
@@ -204,7 +102,6 @@
204102
/*
205103
* X/Open System Interfaces
206104
*/
207-
#define _XOPEN_VERSION 700
208105
/* #define _XOPEN_CRYPT (-1L) */
209106
/* #define _XOPEN_ENH_I18N (-1L) */
210107
#if defined(CONFIG_XSI_REALTIME) || \
@@ -217,10 +114,6 @@
217114
/* #define _XOPEN_REALTIME_THREADS (-1L) */
218115
/* #define _XOPEN_SHM (-1L) */
219116

220-
#ifdef CONFIG_XOPEN_STREAMS
221-
#define _XOPEN_STREAMS _XOPEN_VERSION
222-
#endif
223-
224117
/* #define _XOPEN_UNIX (-1L) */
225118
/* #define _XOPEN_UUCP (-1L) */
226119

include/zephyr/posix/posix_limits.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@
122122
#define POSIX_REC_XFER_ALIGN (4)
123123
#define SYMLINK_MAX _POSIX_SYMLINK_MAX
124124

125+
/* Other invariant values */
126+
#define GETENTROPY_MAX (256)
127+
125128
/* clang-format on */
126129

127130
#endif

include/zephyr/posix/posix_signal.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ struct sigevent {
132132

133133
/* SIGRTMIN and SIGRTMAX defined above */
134134

135+
/* slightly out of order w.r.t. the specification */
135136
#if !defined(_SIGINFO_T_DECLARED) && !defined(__siginfo_t_defined)
136137
typedef struct {
137138
void *si_addr;
@@ -197,6 +198,17 @@ typedef struct {
197198
#define __mcontext_defined
198199
#endif
199200

201+
/* slightly out of order w.r.t. the specification */
202+
#if !defined(_STACK_T_DECLARED) && !defined(__stack_t_defined)
203+
typedef struct {
204+
void *ss_sp;
205+
size_t ss_size;
206+
int ss_flags;
207+
} stack_t;
208+
#define _STACK_T_DECLARED
209+
#define __stack_t_defined
210+
#endif
211+
200212
#if !defined(_UCONTEXT_T_DECLARED) && !defined(__ucontext_t_defined)
201213
typedef struct {
202214
struct ucontext *uc_link;
@@ -208,16 +220,6 @@ typedef struct {
208220
#define __ucontext_defined
209221
#endif
210222

211-
#if !defined(_STACK_T_DECLARED) && !defined(__stack_t_defined)
212-
typedef struct {
213-
void *ss_sp;
214-
size_t ss_size;
215-
int ss_flags;
216-
} stack_t;
217-
#define _STACK_T_DECLARED
218-
#define __stack_t_defined
219-
#endif
220-
221223
#endif /* defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) */
222224

223225
/* Siginfo codes are defined below */

0 commit comments

Comments
 (0)