Skip to content

Commit 3419dda

Browse files
committed
Patch test code to make is more portable
1 parent eff6b3c commit 3419dda

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/test/TestAPI.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,52 +22,48 @@
2222
#ifndef PORTABLE_FMEMOPEN_H
2323
#define PORTABLE_FMEMOPEN_H
2424

25-
#if defined(__APPLE__) || defined(__MACH__)
25+
#if defined(_WIN32)
2626

27-
// macOS does not have fmemopen, but has funopen
27+
// Windows has no fmemopen
2828
static inline FILE* portable_fmemopen(void* buf, size_t size, const char* mode)
2929
{
30-
(void)mode; // Only "wb" or "rb" used in tests
31-
32-
// Simple implementation: use a temporary file and preload the buffer
3330
FILE* f = tmpfile();
31+
3432
if (!f)
3533
return NULL;
3634

3735
if (buf && size > 0 && strchr(mode, 'w') == NULL) {
38-
// reading: preload buffer
3936
fwrite(buf, 1, size, f);
4037
rewind(f);
4138
}
4239

4340
return f;
4441
}
4542

46-
#elif defined(_WIN32)
43+
#else
4744

48-
// Windows also has no fmemopen
45+
// macOS does not have fmemopen, but has funopen
46+
// BSD may not have fmemopen
47+
// Most Linux distros do have fmemopen
4948
static inline FILE* portable_fmemopen(void* buf, size_t size, const char* mode)
5049
{
50+
(void)mode; // Only "wb" or "rb" used in tests
51+
52+
// Simple implementation: use a temporary file and preload the buffer
5153
FILE* f = tmpfile();
54+
5255
if (!f)
5356
return NULL;
5457

5558
if (buf && size > 0 && strchr(mode, 'w') == NULL) {
59+
// reading: preload buffer
5660
fwrite(buf, 1, size, f);
5761
rewind(f);
5862
}
5963

6064
return f;
6165
}
6266

63-
#else
64-
65-
// Linux/glibc supports real fmemopen
66-
static inline FILE* portable_fmemopen(void* buf, size_t size, const char* mode)
67-
{
68-
return fmemopen(buf, size, mode);
69-
}
70-
7167
#endif
7268

7369
#endif

0 commit comments

Comments
 (0)