Skip to content

Commit a0c5221

Browse files
Cleanup of platform/includes.h usage.
- Removed platform/includes usage where possible. - Restored default includes where possible. - Removed unneeded support from platform/windows.h
1 parent 304a351 commit a0c5221

10 files changed

Lines changed: 45 additions & 112 deletions

File tree

libnvme/src/nvme/cleanup.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
#include <stdlib.h>
66

7-
#include <platform/includes.h>
8-
9-
#include "private.h"
7+
#include "private.h" /* for __libnvme_free */
108

119
#define __cleanup(fn) __attribute__((cleanup(fn)))
1210

libnvme/src/nvme/ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
static int nvme_verify_chr(struct libnvme_transport_handle *hdl)
3030
{
3131
static struct stat nvme_stat;
32-
int err = libnvme_fstat(hdl->fd, &nvme_stat);
32+
int err = fstat(hdl->fd, &nvme_stat);
3333

3434
if (err < 0)
3535
return -errno;

libnvme/src/nvme/log.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
#include <stdbool.h>
1313
#include <stdio.h>
1414
#include <time.h>
15-
16-
#include <platform/includes.h>
15+
#include <unistd.h>
1716

1817
#include <libnvme.h>
1918

libnvme/src/nvme/mi-mctp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
#include <stdbool.h>
1313
#include <stdio.h>
1414
#include <stdlib.h>
15+
#include <unistd.h>
1516

16-
#include <platform/includes.h>
17+
#include <sys/ioctl.h>
18+
#include <sys/socket.h>
19+
#include <sys/types.h>
20+
#include <sys/uio.h>
1721

1822
#if HAVE_LINUX_MCTP_H
1923
#include <linux/mctp.h>

libnvme/src/nvme/util.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
#if defined(HAVE_NETDB) || defined(CONFIG_FABRICS)
2020
#include <sys/types.h>
2121
#include <ifaddrs.h>
22+
#include <arpa/inet.h>
23+
#include <netdb.h>
2224
#endif
2325

26+
#include <sys/param.h>
2427
#include <sys/stat.h>
2528
#include <sys/types.h>
2629

27-
#include <platform/includes.h>
28-
2930
#include <ccan/endian/endian.h>
3031
#include <ccan/minmax/minmax.h>
3132

libnvme/src/platform/windows.h

Lines changed: 18 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,27 @@ static inline void libnvme_init(void)
4444
_setmode(_fileno(stderr), O_BINARY);
4545
}
4646

47+
/* Platform-specific UUID generation using BCryptGenRandom */
48+
static inline int random_uuid(unsigned char *uuid, size_t len)
49+
{
50+
NTSTATUS status;
4751

48-
/* sys/param.h compatibility */
52+
status = BCryptGenRandom(NULL, uuid, (ULONG)len,
53+
BCRYPT_USE_SYSTEM_PREFERRED_RNG);
54+
if (!BCRYPT_SUCCESS(status))
55+
return -EIO;
4956

50-
#define MIN(a, b) ((a) < (b) ? (a) : (b))
51-
#define MAX(a, b) ((a) > (b) ? (a) : (b))
57+
return 0;
58+
}
5259

5360

5461
/* errno.h compatibility */
5562

56-
#define EREMOTEIO 121
57-
#define EDQUOT 122
58-
#define ERESTART 85
59-
#define ENOTBLK 15
60-
#define ENAVAIL 119
63+
#define EREMOTEIO 121 // util.c
64+
#define EDQUOT 122 // util.c
65+
#define ERESTART 85 // util.c
66+
#define ENOTBLK 15 // sfx-nvme.c - could they just use libnvme's check for char device instead?
67+
#define ENAVAIL 119 // nvme.c - just used internally, define a custom, internal error code for this?
6168

6269

6370
/* ifaddrs.h compatibility */
@@ -72,21 +79,6 @@ struct ifaddrs {
7279
void *ifa_data;
7380
};
7481

75-
static inline void freeifaddrs(struct ifaddrs *ifa) { (void)ifa; }
76-
77-
/* Platform-specific UUID generation using BCryptGenRandom */
78-
static inline int random_uuid(unsigned char *uuid, size_t len)
79-
{
80-
NTSTATUS status;
81-
82-
status = BCryptGenRandom(NULL, uuid, (ULONG)len,
83-
BCRYPT_USE_SYSTEM_PREFERRED_RNG);
84-
if (!BCRYPT_SUCCESS(status))
85-
return -EIO;
86-
87-
return 0;
88-
}
89-
9082

9183
/* stdio.h POSIX extensions */
9284

@@ -175,29 +167,6 @@ static inline FILE *open_memstream(char **ptr, size_t *sizeloc)
175167
}
176168

177169

178-
/* string.h POSIX extensions */
179-
180-
/* strsep implementation for Windows */
181-
static inline char *strsep(char **stringp, const char *delim)
182-
{
183-
char *start = *stringp;
184-
char *p;
185-
186-
if (start == NULL)
187-
return NULL;
188-
189-
p = strpbrk(start, delim);
190-
if (p) {
191-
*p = '\0';
192-
*stringp = p + 1;
193-
} else {
194-
*stringp = NULL;
195-
}
196-
197-
return start;
198-
}
199-
200-
201170
/* stdlib.h compatibility */
202171

203172
/* Aligned memory allocation function, use platform_aligned_free to free. */
@@ -316,67 +285,17 @@ static inline int sigaction(int signum, const struct sigaction *act,
316285
}
317286

318287

319-
/* fnmatch.h POSIX compatibility - Only used by fabrics - consider removing */
320-
321-
#define FNM_NOMATCH 1
322-
#define FNM_PATHNAME 0x01
323-
324-
/* Basic fnmatch implementation for Windows:
325-
* - Supports '*' (match any sequence, including empty) and
326-
* '?' (match any single character).
327-
* - Ignores flags for now; they are accepted for compatibility.
328-
* Returns 0 on match, FNM_NOMATCH on mismatch.
329-
*/
330-
static inline int fnmatch(const char *pattern, const char *string, int flags)
331-
{
332-
(void)flags; /* flags currently unused */
333-
334-
while (*pattern) {
335-
if (*pattern == '*') {
336-
/* Skip consecutive '*' characters */
337-
while (*pattern == '*')
338-
pattern++;
339-
340-
if (!*pattern)
341-
/* Trailing '*' matches the rest of the string */
342-
return 0;
343-
344-
/* Try to match the remainder of the pattern at each suffix of string */
345-
while (*string) {
346-
if (!fnmatch(pattern, string, flags))
347-
return 0;
348-
string++;
349-
}
350-
/* No match found for pattern suffix after '*' */
351-
return FNM_NOMATCH;
352-
} else if (*pattern == '?') {
353-
/* '?' matches any single character, if present */
354-
if (!*string)
355-
return FNM_NOMATCH;
356-
pattern++;
357-
string++;
358-
} else {
359-
/* Literal character match */
360-
if (*pattern != *string)
361-
return FNM_NOMATCH;
362-
pattern++;
363-
string++;
364-
}
365-
}
366-
367-
/* At end of pattern: match only if we're also at end of string */
368-
return *string ? FNM_NOMATCH : 0;
369-
}
370-
371-
372288
/* limits.h compatibility */
373289

374290
#ifndef NAME_MAX
375291
#define NAME_MAX 260
376292
#endif
377293

378294

295+
/* sys/stat.h compatibility */
296+
379297
/* Windows _mkdir doesn't take mode parameter */
298+
/* _mkdir is defined in <direct.h> */
380299
#define mkdir(path, mode) _mkdir(path)
381300

382301
/* Platform-specific fstat wrapper for libnvme_fd_t */

logging.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <stdint.h>
77
#include <string.h>
88

9-
#include <platform/includes.h>
9+
#include <sys/time.h>
1010

1111
#include <ccan/endian/endian.h>
1212

nvme-print-json.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
#include <errno.h>
55
#include <time.h>
66
#include <sys/types.h>
7-
#include <platform/includes.h>
7+
8+
#ifdef CONFIG_FABRICS
9+
#include <sys/socket.h>
10+
#include <arpa/inet.h>
11+
#endif
812

913
#include <ccan/compiler/compiler.h>
1014

1115
#include <libnvme.h>
16+
1217
#include "nvme-print.h"
1318

1419
#include "util/json.h"

nvme-print-stdout.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
#include <stdlib.h>
66
#include <string.h>
77
#include <time.h>
8-
#include <platform/includes.h>
8+
#include <sys/stat.h>
9+
#include <sys/types.h>
10+
11+
#ifdef CONFIG_FABRICS
12+
#include <sys/socket.h>
13+
#include <arpa/inet.h>
14+
#endif
15+
916
#include <ccan/strset/strset.h>
1017
#include <ccan/htable/htable_type.h>
1118
#include <ccan/htable/htable.h>

util/table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <errno.h>
2121
#include <string.h>
2222

23-
#include <platform/includes.h>
23+
#include <platform/includes.h> /* for reallocarray */
2424

2525
#include "table.h"
2626

0 commit comments

Comments
 (0)