Skip to content
77 changes: 39 additions & 38 deletions include/zephyr/posix/posix_signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ typedef int uid_t;
#define __uid_t_defined
#endif

#if !defined(_TIME_T_DECLARED) && !defined(__time_t_defined)
typedef long time_t;
#define _TIME_T_DECLARED
#define __time_t_defined
#endif
/* time_t must be defined by the libc time.h */
#include <time.h>

#if __STDC_VERSION__ >= 201112L
/* struct timespec must be defined in the libc time.h */
#else
#if !defined(_TIMESPEC_DECLARED) && !defined(__timespec_defined)
struct timespec {
time_t tv_sec;
Expand All @@ -57,6 +57,7 @@ struct timespec {
#define _TIMESPEC_DECLARED
#define __timespec_defined
#endif
#endif

/* sig_atomic_t must be defined by the libc signal.h */

Expand Down Expand Up @@ -97,17 +98,26 @@ typedef struct {

#if defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__)

union sigval; /* forward declaration (to preserve spec order) */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering - can't we keep it as-is?

Copy link
Member Author

@cfriedt cfriedt Oct 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't.

diff --git a/lib/posix/options/Kconfig.device_io b/lib/posix/options/Kconfig.device_io
index 416ccf74a62..71ff6b7b81c 100644
--- a/lib/posix/options/Kconfig.device_io
+++ b/lib/posix/options/Kconfig.device_io
@@ -6,7 +6,7 @@ menu "POSIX device I/O"
 
 config POSIX_DEVICE_IO
        bool "POSIX device I/O"
-       select REQUIRES_FULL_LIBC
+       #select REQUIRES_FULL_LIBC
        select ZVFS
        select ZVFS_POLL
        select ZVFS_SELECT
west build -p -b qemu_riscv64 -t run tests/posix/signals/ -- -DCONFIG_MINIMAL_LIBC=y -DCONFIG_COMPILER_WARNINGS_AS_ERRORS=y
...
/home/cfriedt/zephyrproject/zephyr/include/zephyr/posix/posix_signal.h:109:22: error: field 'sigev_value' has incomplete type
  109 |         union sigval sigev_value;
      |                      ^~~~~~~~~~~

/* slightly out of order w.r.t. the specification */
#if !defined(_SIGVAL_DECLARED) && !defined(__sigval_defined)
union sigval {
int sival_int;
void *sival_ptr;
};
#define _SIGVAL_DECLARED
#define __sigval_defined
#endif

#if !defined(_SIGEVENT_DECLARED) && !defined(__sigevent_defined)
typedef struct {
struct sigevent {
#if defined(_POSIX_THREADS) || defined(__DOXYGEN__)
pthread_attr_t *sigev_thread_attr;
pthread_attr_t *sigev_notify_attributes;
void (*sigev_notify_function)(union sigval value);
#endif
union sigval sigev_value;
int sigev_notify;
int sigev_signo;
} sigevent_t;
};
#define _SIGEVENT_DECLARED
#define __sigevent_defined
#endif
Expand All @@ -120,17 +130,28 @@ typedef struct {

#endif /* defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) */

#if !defined(_SIGVAL_DECLARED) && !defined(__sigval_defined)
union sigval {
int sival_int;
void *sival_ptr;
};
#define _SIGVAL_DECLARED
#define __sigval_defined
#endif

/* SIGRTMIN and SIGRTMAX defined above */

#if !defined(_SIGINFO_T_DECLARED) && !defined(__siginfo_t_defined)
typedef struct {
void *si_addr;
#if defined(_XOPEN_STREAMS) || defined(__DOXYGEN__)
long si_band;
#endif
union sigval si_value;
pid_t si_pid;
uid_t si_uid;
int si_signo;
int si_code;
#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
int si_errno;
#endif
int si_status;
} siginfo_t;
#define _SIGINFO_T_DECLARED
#define __siginfo_t_defined
#endif

#if defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__)

#if !defined(_SIGACTION_DECLARED) && !defined(__sigaction_defined)
Expand Down Expand Up @@ -199,26 +220,6 @@ typedef struct {

#endif /* defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) */

#if !defined(_SIGINFO_T_DECLARED) && !defined(__siginfo_t_defined)
typedef struct {
void *si_addr;
#if defined(_XOPEN_STREAMS) || defined(__DOXYGEN__)
long si_band;
#endif
union sigval si_value;
pid_t si_pid;
uid_t si_uid;
int si_signo;
int si_code;
#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__)
int si_errno;
#endif
int si_status;
} siginfo_t;
#define _SIGINFO_T_DECLARED
#define __siginfo_t_defined
#endif

/* Siginfo codes are defined below */

#if !defined(_SIGHANDLER_T_DECLARED) && !defined(__sighandler_t_defined)
Expand Down
4 changes: 2 additions & 2 deletions include/zephyr/posix/posix_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ struct sigevent;
/* struct timespec must be defined in the libc time.h */
#else
#if !defined(_TIMESPEC_DECLARED) && !defined(__timespec_defined)
typedef struct {
struct timespec {
time_t tv_sec;
long tv_nsec;
} timespec_t;
};
#define _TIMESPEC_DECLARED
#define __timespec_defined
#endif
Expand Down
2 changes: 2 additions & 0 deletions lib/libc/arcmwdt/include/sys/timespec.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#include <sys/_timespec.h>

#define _TIMESPEC_DECLARED

struct itimerspec {
struct timespec it_interval; /* Timer interval */
struct timespec it_value; /* Timer expiration */
Expand Down
1 change: 1 addition & 0 deletions lib/libc/armstdc/include/sys/_timespec.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ struct timespec {
time_t tv_sec;
long tv_nsec;
};
#define __timespec_defined

#endif /* ZEPHYR_LIB_LIBC_ARMSTDC_INCLUDE_SYS__TIMESPEC_H_ */
1 change: 1 addition & 0 deletions lib/libc/armstdc/include/sys/_timeval.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
#define __timeval_defined

#endif /* ZEPHYR_LIB_LIBC_ARMSTDC_INCLUDE_SYS__TIMEVAL_H_ */
1 change: 1 addition & 0 deletions lib/libc/iar/include/sys/_timeval.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
#define __timeval_defined

#endif /* ZEPHYR_LIB_LIBC_IAR_INCLUDE_SYS__TIMEVAL_H_ */
4 changes: 4 additions & 0 deletions lib/libc/minimal/include/sys/_timespec.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ typedef _TIME_T_ time_t;
typedef _SUSECONDS_T_ suseconds_t;
#endif

#if !defined(_TIMESPEC_DECLARED) && !defined(__timespec_defined)
struct timespec {
time_t tv_sec;
long tv_nsec;
};
#define __timespec_defined
#define _TIMESPEC_DECLARED
#endif

#endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS__TIMESPEC_H_ */
4 changes: 4 additions & 0 deletions lib/libc/minimal/include/sys/_timeval.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ typedef _TIME_T_ time_t;
typedef _SUSECONDS_T_ suseconds_t;
#endif

#if !defined(_TIMEVAL_DECLARED) && !defined(__timeval_defined)
struct timeval {
time_t tv_sec;
suseconds_t tv_usec;
};
#define _TIMEVAL_DECLARED
#define __timeval_defined
#endif

#endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SYS__TIMEVAL_H_ */
5 changes: 5 additions & 0 deletions lib/libc/newlib/include/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
#undef sigdelset
#undef sigismember

#if defined(_POSIX_REALTIME_SIGNALS)
#define _SIGEVENT_DECLARED
#define _SIGVAL_DECLARED
#endif

#endif /* defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) */

#endif /* ZEPHYR_LIB_LIBC_NEWLIB_INCLUDE_SIGNAL_H_ */
14 changes: 14 additions & 0 deletions lib/libc/newlib/include/sys/_timespec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright The Zephyr Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_LIB_LIBC_NEWLIB_INCLUDE_SYS__TIMESPEC_H_
#define ZEPHYR_LIB_LIBC_NEWLIB_INCLUDE_SYS__TIMESPEC_H_

#include_next <sys/_timespec.h>

#define _TIMESPEC_DECLARED

#endif /* ZEPHYR_LIB_LIBC_NEWLIB_INCLUDE_SYS__TIMESPEC_H_ */
14 changes: 14 additions & 0 deletions lib/libc/newlib/include/sys/_timeval.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright The Zephyr Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_LIB_LIBC_NEWLIB_INCLUDE_SYS__TIMEVAL_H_
#define ZEPHYR_LIB_LIBC_NEWLIB_INCLUDE_SYS__TIMEVAL_H_

#include_next <sys/_timeval.h>

#define _TIMEVAL_DECLARED

#endif /* ZEPHYR_LIB_LIBC_NEWLIB_INCLUDE_SYS__TIMEVAL_H_ */
5 changes: 5 additions & 0 deletions lib/libc/picolibc/include/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ int pthread_sigmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT
#undef sigdelset
#undef sigismember

#if defined(_POSIX_REALTIME_SIGNALS)
#define _SIGEVENT_DECLARED
#define _SIGVAL_DECLARED
#endif

#endif /* defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) */

#endif /* ZEPHYR_LIB_LIBC_PICOLIBC_INCLUDE_SIGNAL_H_ */
14 changes: 14 additions & 0 deletions lib/libc/picolibc/include/sys/_timespec.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright The Zephyr Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_LIB_LIBC_PICOLIBC_INCLUDE_SYS__TIMESPEC_H_
#define ZEPHYR_LIB_LIBC_PICOLIBC_INCLUDE_SYS__TIMESPEC_H_

#include_next <sys/_timespec.h>

#define _TIMESPEC_DECLARED

#endif /* ZEPHYR_LIB_LIBC_PICOLIBC_INCLUDE_SYS__TIMESPEC_H_ */
14 changes: 14 additions & 0 deletions lib/libc/picolibc/include/sys/_timeval.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright The Zephyr Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_LIB_LIBC_PICOLIBC_INCLUDE_SYS__TIMEVAL_H_
#define ZEPHYR_LIB_LIBC_PICOLIBC_INCLUDE_SYS__TIMEVAL_H_

#include_next <sys/_timeval.h>

#define _TIMEVAL_DECLARED

#endif /* ZEPHYR_LIB_LIBC_PICOLIBC_INCLUDE_SYS__TIMEVAL_H_ */