Skip to content

Commit 7d28895

Browse files
Moved remaining compatibility helpers into new lib-compat.h
Moved libnvme-specific compatibility types, definitions, and methods into new nvme/lib-compat.h and removed platform/*.h. Also cleaned up and standardized formatting of compatibility headers.
1 parent bcd43d5 commit 7d28895

10 files changed

Lines changed: 30 additions & 64 deletions

File tree

libnvme/src/meson.build

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,3 @@ if want_mi
197197
install_mode: mode,
198198
)
199199
endif
200-
201-
202-
# Install platform abstraction headers
203-
install_headers([
204-
'platform/includes.h',
205-
'platform/linux.h',
206-
'platform/windows.h',
207-
],
208-
subdir: 'platform',
209-
install_mode: mode,
210-
)
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,46 @@
1-
// SPDX-License-Identifier: LGPL-2.1-or-later
1+
/* SPDX-License-Identifier: LGPL-2.1-or-later */
22
/*
33
* This file is part of libnvme.
4-
* Copyright (c) 2025 Micron Technology, Inc.
4+
* Copyright (c) 2026 Micron Technology, Inc.
55
*
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]>
710
*/
8-
911
#pragma once
1012

11-
/* Windows-specific includes */
13+
#if defined(_WIN32) || defined(_WIN64)
14+
1215
#define WIN32_LEAN_AND_MEAN /* keeps windows.h from including winsock.*/
1316
#include <windows.h>
1417

1518
#include <fcntl.h>
1619
#include <stdio.h>
1720

18-
19-
/* Platform compatibility helper types and methods */
20-
2121
typedef HANDLE libnvme_fd_t;
22+
2223
#define TEST_FD INVALID_HANDLE_VALUE
2324
#define INIT_FD nullptr
2425

2526
/*
2627
* Set stdout and stderr to binary mode to prevent Windows text-mode
2728
* translation from converting LF to CRLF and corrupting raw binary output.
28-
* Called once at startup from main().
29+
* Call once at startup.
2930
*/
3031
static inline void libnvme_init(void)
3132
{
3233
_setmode(_fileno(stdout), O_BINARY);
3334
_setmode(_fileno(stderr), O_BINARY);
3435
}
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

libnvme/src/nvme/lib.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
#include <stdbool.h>
1212
#include <stdio.h>
1313

14+
#include <nvme/lib-compat.h>
1415
#include <nvme/lib-types.h>
1516
#include <nvme/stdlib.h>
1617
#include <nvme/unistd.h>
1718

18-
#include <platform/includes.h> /* for libnvme_fd_t */
19-
2019
enum libnvme_log_level {
2120
LIBNVME_LOG_ERR = 0,
2221
LIBNVME_LOG_WARN = 1,

libnvme/src/nvme/malloc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Provides functionality that may be missing on some platforms.
88
* Compatibility is not comprehensive. Only functionality required by
99
* nvme-cli and libnvme is included.
10-
*
10+
*
1111
* Authors: Broc Going <[email protected]>
1212
* Brandon Capener <[email protected]>
1313
*/
@@ -23,4 +23,4 @@ static inline size_t malloc_usable_size(void *ptr)
2323
return _msize(ptr);
2424
}
2525

26-
#endif /* _WIN32 */
26+
#endif

libnvme/src/nvme/private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <sys/stat.h>
1111
#include <sys/types.h>
1212

13-
#include <platform/includes.h> /* for libnvme_fd_t */
13+
#include <nvme/lib-compat.h>
1414

1515
#include <ccan/list/list.h>
1616

libnvme/src/nvme/signal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Provides functionality that may be missing on some platforms.
88
* Compatibility is not comprehensive. Only functionality required by
99
* nvme-cli and libnvme is included.
10-
*
11-
* Authors: Brandon Busacker <bbusacker@micron.com>
12-
* Broc Going <bgoing@micron.com>
10+
*
11+
* Authors: Broc Going <bgoing@micron.com>
12+
* Brandon Busacker <bbusacker@micron.com>
1313
*/
1414
#pragma once
1515

libnvme/src/nvme/stdio.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
* Compatibility is not comprehensive. Only functionality required by
99
* nvme-cli and libnvme is included.
1010
*
11-
* Authors: Brandon Capener <bcapener@micron.com>
11+
* Authors: Broc Going <bgoing@micron.com>
1212
* Brandon Busacker <[email protected]>
1313
*/
14-
1514
#pragma once
1615

1716
#include <stdio.h>

libnvme/src/nvme/stdlib.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
* Provides functionality that may be missing on some platforms.
88
* Compatibility is not comprehensive. Only functionality required by
99
* nvme-cli and libnvme is included.
10-
*
10+
*
1111
* Authors: Broc Going <[email protected]>
1212
* Brandon Capener <[email protected]>
1313
*/
14-
1514
#pragma once
1615

1716
#include <stdlib.h>

libnvme/src/platform/includes.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

libnvme/src/platform/linux.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)