|
1 | | -// SPDX-License-Identifier: LGPL-2.1-or-later |
| 1 | +/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
2 | 2 | /* |
3 | 3 | * This file is part of libnvme. |
4 | | - * Copyright (c) 2025 Micron Technology, Inc. |
| 4 | + * Copyright (c) 2026 Micron Technology, Inc. |
5 | 5 | * |
6 | | - * Windows platform-specific definitions and includes. |
| 6 | + * Cross-platform compatibility definitions, types, and utilities. |
| 7 | + * |
| 8 | + * Authors: Broc Going <[email protected]> |
| 9 | + * Brandon Busacker <[email protected]> |
7 | 10 | */ |
8 | | - |
9 | 11 | #pragma once |
10 | 12 |
|
11 | | -/* Windows-specific includes */ |
| 13 | +#if defined(_WIN32) || defined(_WIN64) |
| 14 | + |
12 | 15 | #define WIN32_LEAN_AND_MEAN /* keeps windows.h from including winsock.*/ |
13 | 16 | #include <windows.h> |
14 | 17 |
|
15 | 18 | #include <fcntl.h> |
16 | 19 | #include <stdio.h> |
17 | 20 |
|
18 | | - |
19 | | -/* Platform compatibility helper types and methods */ |
20 | | - |
21 | 21 | typedef HANDLE libnvme_fd_t; |
| 22 | + |
22 | 23 | #define TEST_FD INVALID_HANDLE_VALUE |
23 | 24 | #define INIT_FD nullptr |
24 | 25 |
|
25 | 26 | /* |
26 | 27 | * Set stdout and stderr to binary mode to prevent Windows text-mode |
27 | 28 | * translation from converting LF to CRLF and corrupting raw binary output. |
28 | | - * Called once at startup from main(). |
| 29 | + * Call once at startup. |
29 | 30 | */ |
30 | 31 | static inline void libnvme_init(void) |
31 | 32 | { |
32 | 33 | _setmode(_fileno(stdout), O_BINARY); |
33 | 34 | _setmode(_fileno(stderr), O_BINARY); |
34 | 35 | } |
| 36 | + |
| 37 | +#else |
| 38 | + |
| 39 | +typedef int libnvme_fd_t; |
| 40 | +#define TEST_FD 0xFD |
| 41 | +#define INIT_FD -1 |
| 42 | + |
| 43 | +/* Platform initialization - no-op on Linux */ |
| 44 | +static inline void libnvme_init(void) {} |
| 45 | + |
| 46 | +#endif |
0 commit comments