@@ -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 */
0 commit comments