Skip to content

Commit

Permalink
libc: minimal: declare sig_atomic_t and signal()
Browse files Browse the repository at this point in the history
We don't actually implement signal() in Zephyr, but some users
require the declaration.

Additionally, typedef sig_atomic_t since it is part of ISO.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
  • Loading branch information
cfriedt committed Aug 9, 2023
1 parent 135654e commit 9bd8c7a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/libc/minimal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(STRERROR_TABLE_H ${GEN_DIR}/libc/minimal/strerror_table.h)
zephyr_library_cc_option(-fno-builtin)

zephyr_library_sources(
source/signal/signal.c
source/stdlib/atoi.c
source/stdlib/strtol.c
source/stdlib/strtoul.c
Expand Down
29 changes: 29 additions & 0 deletions lib/libc/minimal/include/signal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2023 Meta
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SIGNAL_H_
#define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SIGNAL_H_

#define SIG_DFL ((sighandler_t)0)
#define SIG_ERR ((sighandler_t)1)
#define SIG_IGN ((sighandler_t)-1)

#ifdef __cplusplus
extern "C" {
#endif

typedef int sig_atomic_t; /* Atomic entity type (ANSI) */

/* Note: sighandler_t is a gnu-ism, but it simplifies the declaration below */
typedef void (*sighandler_t)(int signo);

sighandler_t signal(int signum, sighandler_t handler);

#ifdef __cplusplus
}
#endif

#endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SIGNAL_H_ */
12 changes: 12 additions & 0 deletions lib/libc/minimal/source/signal/signal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2023 Meta
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <signal.h>

sighandler_t signal(int signum, sighandler_t handler)
{
return SIG_DFL;
}

0 comments on commit 9bd8c7a

Please sign in to comment.