From cc6544031549d62030714525d76cd582b7b5fd96 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Mon, 29 Oct 2018 06:34:25 +0000 Subject: [PATCH] ifdef out all use of libc's FILE in libxmp-lite git-svn-id: https://svn.eduke32.com/eduke32@7138 1a8010ca-5511-0410-912e-c29ae57300e0 --- source/libxmp-lite/include/libxmp-lite/xmp.h | 6 +++ source/libxmp-lite/src/common.h | 2 + source/libxmp-lite/src/dataio.c | 2 + source/libxmp-lite/src/hio.c | 48 ++++++++++++++++++++ source/libxmp-lite/src/hio.h | 10 ++++ source/libxmp-lite/src/load.c | 8 ++++ source/libxmp-lite/src/smix.c | 2 + source/libxmp-lite/src/tempfile.h | 7 --- 8 files changed, 78 insertions(+), 7 deletions(-) delete mode 100644 source/libxmp-lite/src/tempfile.h diff --git a/source/libxmp-lite/include/libxmp-lite/xmp.h b/source/libxmp-lite/include/libxmp-lite/xmp.h index 47609e3a3..799deb28d 100644 --- a/source/libxmp-lite/include/libxmp-lite/xmp.h +++ b/source/libxmp-lite/include/libxmp-lite/xmp.h @@ -322,8 +322,10 @@ EXPORT extern const unsigned int xmp_vercode; EXPORT xmp_context xmp_create_context (void); EXPORT void xmp_free_context (xmp_context); +#ifdef EDUKE32_DISABLED EXPORT int xmp_test_module (char *, struct xmp_test_info *); EXPORT int xmp_load_module (xmp_context, char *); +#endif EXPORT void xmp_scan_module (xmp_context); EXPORT void xmp_release_module (xmp_context); EXPORT int xmp_start_player (xmp_context, int, int); @@ -346,7 +348,9 @@ EXPORT int xmp_set_player (xmp_context, int, int); EXPORT int xmp_get_player (xmp_context, int); EXPORT int xmp_set_instrument_path (xmp_context, char *); EXPORT int xmp_load_module_from_memory (xmp_context, void *, long); +#ifdef EDUKE32_DISABLED EXPORT int xmp_load_module_from_file (xmp_context, void *, long); +#endif /* External sample mixer API */ EXPORT int xmp_start_smix (xmp_context, int, int); @@ -354,7 +358,9 @@ EXPORT void xmp_end_smix (xmp_context); EXPORT int xmp_smix_play_instrument(xmp_context, int, int, int, int); EXPORT int xmp_smix_play_sample (xmp_context, int, int, int, int); EXPORT int xmp_smix_channel_pan (xmp_context, int, int); +#ifdef EDUKE32_DISABLED EXPORT int xmp_smix_load_sample (xmp_context, int, char *); +#endif EXPORT int xmp_smix_release_sample (xmp_context, int); #ifdef __cplusplus diff --git a/source/libxmp-lite/src/common.h b/source/libxmp-lite/src/common.h index 7bb5b84f0..2290606d1 100644 --- a/source/libxmp-lite/src/common.h +++ b/source/libxmp-lite/src/common.h @@ -415,6 +415,7 @@ int libxmp_scan_sequences (struct context_data *); int libxmp_get_sequence (struct context_data *, int); int libxmp_set_player_mode (struct context_data *); +#ifdef EDUKE32_DISABLED int8 read8s (FILE *, int *err); uint8 read8 (FILE *, int *err); uint16 read16l (FILE *, int *err); @@ -431,6 +432,7 @@ void write16b (FILE *, uint16); void write32l (FILE *, uint32); void write32b (FILE *, uint32); int move_data (FILE *, FILE *, int); +#endif uint16 readmem16l (const uint8 *); uint16 readmem16b (const uint8 *); diff --git a/source/libxmp-lite/src/dataio.c b/source/libxmp-lite/src/dataio.c index 4f24f0f76..c4c2253e9 100644 --- a/source/libxmp-lite/src/dataio.c +++ b/source/libxmp-lite/src/dataio.c @@ -34,6 +34,7 @@ } while (0) +#ifdef EDUKE32_DISABLED uint8 read8(FILE *f, int *err) { int a; @@ -155,6 +156,7 @@ uint32 read32b(FILE *f, int *err) set_error(ferror(f) ? errno : EOF); return 0xffffffff; } +#endif uint16 readmem16l(const uint8 *m) { diff --git a/source/libxmp-lite/src/hio.c b/source/libxmp-lite/src/hio.c index 42f432198..e2356421d 100644 --- a/source/libxmp-lite/src/hio.c +++ b/source/libxmp-lite/src/hio.c @@ -28,6 +28,7 @@ #include "hio.h" #include "mdataio.h" +#ifdef EDUKE32_DISABLED static long get_size(FILE *f) { long size, pos; @@ -46,19 +47,24 @@ static long get_size(FILE *f) return pos; } } +#endif int8 hio_read8s(HIO_HANDLE *h) { +#ifdef EDUKE32_DISABLED int err; +#endif int8 ret = 0; switch (HIO_HANDLE_TYPE(h)) { +#ifdef EDUKE32_DISABLED case HIO_HANDLE_TYPE_FILE: ret = read8s(h->handle.file, &err); if (err != 0) { h->error = err; } break; +#endif case HIO_HANDLE_TYPE_MEMORY: ret = mread8s(h->handle.mem); break; @@ -69,16 +75,20 @@ int8 hio_read8s(HIO_HANDLE *h) uint8 hio_read8(HIO_HANDLE *h) { +#ifdef EDUKE32_DISABLED int err; +#endif uint8 ret = 0; switch (HIO_HANDLE_TYPE(h)) { +#ifdef EDUKE32_DISABLED case HIO_HANDLE_TYPE_FILE: ret = read8(h->handle.file, &err); if (err != 0) { h->error = err; } break; +#endif case HIO_HANDLE_TYPE_MEMORY: ret = mread8(h->handle.mem); break; @@ -89,16 +99,20 @@ uint8 hio_read8(HIO_HANDLE *h) uint16 hio_read16l(HIO_HANDLE *h) { +#ifdef EDUKE32_DISABLED int err; +#endif uint16 ret = 0; switch (HIO_HANDLE_TYPE(h)) { +#ifdef EDUKE32_DISABLED case HIO_HANDLE_TYPE_FILE: ret = read16l(h->handle.file, &err); if (err != 0) { h->error = err; } break; +#endif case HIO_HANDLE_TYPE_MEMORY: ret = mread16l(h->handle.mem); break; @@ -109,16 +123,20 @@ uint16 hio_read16l(HIO_HANDLE *h) uint16 hio_read16b(HIO_HANDLE *h) { +#ifdef EDUKE32_DISABLED int err; +#endif uint16 ret = 0; switch (HIO_HANDLE_TYPE(h)) { +#ifdef EDUKE32_DISABLED case HIO_HANDLE_TYPE_FILE: ret = read16b(h->handle.file, &err); if (err != 0) { h->error = err; } break; +#endif case HIO_HANDLE_TYPE_MEMORY: ret = mread16b(h->handle.mem); break; @@ -129,16 +147,20 @@ uint16 hio_read16b(HIO_HANDLE *h) uint32 hio_read24l(HIO_HANDLE *h) { +#ifdef EDUKE32_DISABLED int err; +#endif uint32 ret = 0; switch (HIO_HANDLE_TYPE(h)) { +#ifdef EDUKE32_DISABLED case HIO_HANDLE_TYPE_FILE: ret = read24l(h->handle.file, &err); if (err != 0) { h->error = err; } break; +#endif case HIO_HANDLE_TYPE_MEMORY: ret = mread24l(h->handle.mem); break; @@ -149,16 +171,20 @@ uint32 hio_read24l(HIO_HANDLE *h) uint32 hio_read24b(HIO_HANDLE *h) { +#ifdef EDUKE32_DISABLED int err; +#endif uint32 ret = 0; switch (HIO_HANDLE_TYPE(h)) { +#ifdef EDUKE32_DISABLED case HIO_HANDLE_TYPE_FILE: ret = read24b(h->handle.file, &err); if (err != 0) { h->error = err; } break; +#endif case HIO_HANDLE_TYPE_MEMORY: ret = mread24b(h->handle.mem); break; @@ -169,16 +195,20 @@ uint32 hio_read24b(HIO_HANDLE *h) uint32 hio_read32l(HIO_HANDLE *h) { +#ifdef EDUKE32_DISABLED int err; +#endif uint32 ret = 0; switch (HIO_HANDLE_TYPE(h)) { +#ifdef EDUKE32_DISABLED case HIO_HANDLE_TYPE_FILE: ret = read32l(h->handle.file, &err); if (err != 0) { h->error = err; } break; +#endif case HIO_HANDLE_TYPE_MEMORY: ret = mread32l(h->handle.mem); break; @@ -189,16 +219,20 @@ uint32 hio_read32l(HIO_HANDLE *h) uint32 hio_read32b(HIO_HANDLE *h) { +#ifdef EDUKE32_DISABLED int err; +#endif uint32 ret = 0; switch (HIO_HANDLE_TYPE(h)) { +#ifdef EDUKE32_DISABLED case HIO_HANDLE_TYPE_FILE: ret = read32b(h->handle.file, &err); if (err != 0) { h->error = err; } break; +#endif case HIO_HANDLE_TYPE_MEMORY: ret = mread32b(h->handle.mem); } @@ -211,6 +245,7 @@ size_t hio_read(void *buf, size_t size, size_t num, HIO_HANDLE *h) size_t ret = 0; switch (HIO_HANDLE_TYPE(h)) { +#ifdef EDUKE32_DISABLED case HIO_HANDLE_TYPE_FILE: ret = fread(buf, size, num, h->handle.file); if (ret != num) { @@ -221,6 +256,7 @@ size_t hio_read(void *buf, size_t size, size_t num, HIO_HANDLE *h) } } break; +#endif case HIO_HANDLE_TYPE_MEMORY: ret = mread(buf, size, num, h->handle.mem); if (ret != num) { @@ -237,12 +273,14 @@ int hio_seek(HIO_HANDLE *h, long offset, int whence) int ret = -1; switch (HIO_HANDLE_TYPE(h)) { +#ifdef EDUKE32_DISABLED case HIO_HANDLE_TYPE_FILE: ret = fseek(h->handle.file, offset, whence); if (ret < 0) { h->error = errno; } break; +#endif case HIO_HANDLE_TYPE_MEMORY: ret = mseek(h->handle.mem, offset, whence); if (ret < 0) { @@ -259,12 +297,14 @@ long hio_tell(HIO_HANDLE *h) long ret = -1; switch (HIO_HANDLE_TYPE(h)) { +#ifdef EDUKE32_DISABLED case HIO_HANDLE_TYPE_FILE: ret = ftell(h->handle.file); if (ret < 0) { h->error = errno; } break; +#endif case HIO_HANDLE_TYPE_MEMORY: ret = mtell(h->handle.mem); if (ret < 0) { @@ -279,8 +319,10 @@ long hio_tell(HIO_HANDLE *h) int hio_eof(HIO_HANDLE *h) { switch (HIO_HANDLE_TYPE(h)) { +#ifdef EDUKE32_DISABLED case HIO_HANDLE_TYPE_FILE: return feof(h->handle.file); +#endif case HIO_HANDLE_TYPE_MEMORY: return meof(h->handle.mem); default: @@ -295,6 +337,7 @@ int hio_error(HIO_HANDLE *h) return error; } +#ifdef EDUKE32_DISABLED HIO_HANDLE *hio_open(const void *path, const char *mode) { HIO_HANDLE *h; @@ -322,6 +365,7 @@ HIO_HANDLE *hio_open(const void *path, const char *mode) err: return NULL; } +#endif HIO_HANDLE *hio_open_mem(const void *ptr, long size) { @@ -339,6 +383,7 @@ HIO_HANDLE *hio_open_mem(const void *ptr, long size) return h; } +#ifdef EDUKE32_DISABLED HIO_HANDLE *hio_open_file(FILE *f) { HIO_HANDLE *h; @@ -354,15 +399,18 @@ HIO_HANDLE *hio_open_file(FILE *f) return h; } +#endif int hio_close(HIO_HANDLE *h) { int ret; switch (HIO_HANDLE_TYPE(h)) { +#ifdef EDUKE32_DISABLED case HIO_HANDLE_TYPE_FILE: ret = fclose(h->handle.file); break; +#endif case HIO_HANDLE_TYPE_MEMORY: ret = mclose(h->handle.mem); break; diff --git a/source/libxmp-lite/src/hio.h b/source/libxmp-lite/src/hio.h index 91f2c04a0..cedcbb6a2 100644 --- a/source/libxmp-lite/src/hio.h +++ b/source/libxmp-lite/src/hio.h @@ -1,20 +1,26 @@ #ifndef XMP_HIO_H #define XMP_HIO_H +#ifdef EDUKE32_DISABLED #include #include +#endif #include #include "memio.h" #define HIO_HANDLE_TYPE(x) ((x)->type) typedef struct { +#ifdef EDUKE32_DISABLED #define HIO_HANDLE_TYPE_FILE 0 +#endif #define HIO_HANDLE_TYPE_MEMORY 1 int type; long size; union { +#ifdef EDUKE32_DISABLED FILE *file; +#endif MFILE *mem; } handle; int error; @@ -33,9 +39,13 @@ int hio_seek (HIO_HANDLE *, long, int); long hio_tell (HIO_HANDLE *); int hio_eof (HIO_HANDLE *); int hio_error (HIO_HANDLE *); +#ifdef EDUKE32_DISABLED HIO_HANDLE *hio_open (const void *, const char *); +#endif HIO_HANDLE *hio_open_mem (const void *, long); +#ifdef EDUKE32_DISABLED HIO_HANDLE *hio_open_file (FILE *); +#endif int hio_close (HIO_HANDLE *); long hio_size (HIO_HANDLE *); diff --git a/source/libxmp-lite/src/load.c b/source/libxmp-lite/src/load.c index 3b6fc8619..ee873d933 100644 --- a/source/libxmp-lite/src/load.c +++ b/source/libxmp-lite/src/load.c @@ -34,7 +34,9 @@ #include "format.h" #include "list.h" #include "hio.h" +#ifndef LIBXMP_CORE_PLAYER #include "tempfile.h" +#endif #ifndef LIBXMP_CORE_PLAYER #if !defined(HAVE_POPEN) && defined(WIN32) @@ -282,6 +284,7 @@ static char *get_basename(char *name) } #endif /* LIBXMP_CORE_PLAYER */ +#ifdef EDUKE32_DISABLED int xmp_test_module(char *path, struct xmp_test_info *info) { HIO_HANDLE *h; @@ -361,6 +364,7 @@ int xmp_test_module(char *path, struct xmp_test_info *info) #endif return ret; } +#endif static int load_module(xmp_context opaque, HIO_HANDLE *h) { @@ -464,6 +468,7 @@ static int load_module(xmp_context opaque, HIO_HANDLE *h) return -XMP_ERROR_LOAD; } +#ifdef EDUKE32_DISABLED int xmp_load_module(xmp_context opaque, char *path) { struct context_data *ctx = (struct context_data *)opaque; @@ -543,6 +548,7 @@ int xmp_load_module(xmp_context opaque, char *path) return ret; #endif } +#endif int xmp_load_module_from_memory(xmp_context opaque, void *mem, long size) { @@ -573,6 +579,7 @@ int xmp_load_module_from_memory(xmp_context opaque, void *mem, long size) return ret; } +#ifdef EDUKE32_DISABLED int xmp_load_module_from_file(xmp_context opaque, void *file, long size) { struct context_data *ctx = (struct context_data *)opaque; @@ -598,6 +605,7 @@ int xmp_load_module_from_file(xmp_context opaque, void *file, long size) return ret; } +#endif void xmp_release_module(xmp_context opaque) { diff --git a/source/libxmp-lite/src/smix.c b/source/libxmp-lite/src/smix.c index 0e1f56bff..bf501d7c3 100644 --- a/source/libxmp-lite/src/smix.c +++ b/source/libxmp-lite/src/smix.c @@ -172,6 +172,7 @@ int xmp_smix_channel_pan(xmp_context opaque, int chn, int pan) return 0; } +#ifdef EDUKE32_DISABLED int xmp_smix_load_sample(xmp_context opaque, int num, char *path) { struct context_data *ctx = (struct context_data *)opaque; @@ -288,6 +289,7 @@ int xmp_smix_load_sample(xmp_context opaque, int num, char *path) err: return retval; } +#endif int xmp_smix_release_sample(xmp_context opaque, int num) { diff --git a/source/libxmp-lite/src/tempfile.h b/source/libxmp-lite/src/tempfile.h deleted file mode 100644 index f3c8f77d9..000000000 --- a/source/libxmp-lite/src/tempfile.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef XMP_PLATFORM_H -#define XMP_PLATFORM_H - -FILE *make_temp_file(char **); -void unlink_temp_file(char *); - -#endif