File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /* SPDX-License-Identifier: LGPL-2.1-or-later */
2+ /*
3+ * This file is part of libnvme.
4+ * Copyright (c) 2026 Micron Technology, Inc.
5+ *
6+ * Cross-platform compatibility for signal.h.
7+ * Provides functionality that may be missing on some platforms.
8+ * Compatibility is not comprehensive. Only functionality required by
9+ * nvme-cli and libnvme is included.
10+ *
11+ * Authors: Brandon Busacker <[email protected] > 12+ 13+ */
14+ #pragma once
15+
16+ #include <signal.h>
17+
18+ #if defined(_WIN32 ) || defined(_WIN64 )
19+
20+ /* signal.h POSIX compatibility - Windows doesn't have sigaction */
21+
22+ struct sigaction {
23+ void (* sa_handler )(int );
24+ int sa_flags ;
25+ int sa_mask ; /* simplified - normally sigset_t */
26+ };
27+
28+ static inline int sigemptyset (int * set )
29+ {
30+ * set = 0 ;
31+ return 0 ;
32+ }
33+
34+ /*
35+ * Simplified signal handling using Windows signal() function
36+ * This is sufficient for handling SIGINT with no mask or flags.
37+ */
38+ static inline int sigaction (int signum , const struct sigaction * act ,
39+ struct sigaction * oldact )
40+ {
41+ (void )oldact ; /* ignore old action for simplicity */
42+ if (act && act -> sa_handler ) {
43+ signal (signum , act -> sa_handler );
44+ return 0 ;
45+ }
46+ return -1 ;
47+ }
48+
49+ #endif
Original file line number Diff line number Diff line change @@ -43,33 +43,3 @@ static inline void libnvme_init(void)
4343 _setmode (_fileno (stdout ), O_BINARY );
4444 _setmode (_fileno (stderr ), O_BINARY );
4545}
46-
47-
48- /* signal.h POSIX compatibility - Windows doesn't have sigaction */
49-
50- struct sigaction {
51- void (* sa_handler )(int );
52- int sa_flags ;
53- int sa_mask ; /* simplified - normally sigset_t */
54- };
55-
56- static inline int sigemptyset (int * set )
57- {
58- * set = 0 ;
59- return 0 ;
60- }
61-
62- /*
63- * Simplified signal handling using Windows signal() function
64- * This is sufficient for handling SIGINT with no mask or flags.
65- */
66- static inline int sigaction (int signum , const struct sigaction * act ,
67- struct sigaction * oldact )
68- {
69- (void )oldact ; /* ignore old action for simplicity */
70- if (act && act -> sa_handler ) {
71- signal (signum , act -> sa_handler );
72- return 0 ;
73- }
74- return -1 ;
75- }
Original file line number Diff line number Diff line change 77#include <unistd.h>
88#include <inttypes.h>
99
10+ #include <nvme/signal.h>
1011#include <libnvme.h>
1112
1213#include "common.h"
Original file line number Diff line number Diff line change 33#include <errno.h>
44#include <stddef.h>
55
6- #include <platform/includes .h>
6+ #include <nvme/signal .h>
77
88#include "sighdl.h"
99
You can’t perform that action at this time.
0 commit comments