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
This commit is contained in:
hendricks266 2018-10-29 06:34:25 +00:00
parent 696ddec8a8
commit cc65440315
8 changed files with 78 additions and 7 deletions

View file

@ -322,8 +322,10 @@ EXPORT extern const unsigned int xmp_vercode;
EXPORT xmp_context xmp_create_context (void); EXPORT xmp_context xmp_create_context (void);
EXPORT void xmp_free_context (xmp_context); EXPORT void xmp_free_context (xmp_context);
#ifdef EDUKE32_DISABLED
EXPORT int xmp_test_module (char *, struct xmp_test_info *); EXPORT int xmp_test_module (char *, struct xmp_test_info *);
EXPORT int xmp_load_module (xmp_context, char *); EXPORT int xmp_load_module (xmp_context, char *);
#endif
EXPORT void xmp_scan_module (xmp_context); EXPORT void xmp_scan_module (xmp_context);
EXPORT void xmp_release_module (xmp_context); EXPORT void xmp_release_module (xmp_context);
EXPORT int xmp_start_player (xmp_context, int, int); 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_get_player (xmp_context, int);
EXPORT int xmp_set_instrument_path (xmp_context, char *); EXPORT int xmp_set_instrument_path (xmp_context, char *);
EXPORT int xmp_load_module_from_memory (xmp_context, void *, long); 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); EXPORT int xmp_load_module_from_file (xmp_context, void *, long);
#endif
/* External sample mixer API */ /* External sample mixer API */
EXPORT int xmp_start_smix (xmp_context, int, int); 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_instrument(xmp_context, int, int, int, int);
EXPORT int xmp_smix_play_sample (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); EXPORT int xmp_smix_channel_pan (xmp_context, int, int);
#ifdef EDUKE32_DISABLED
EXPORT int xmp_smix_load_sample (xmp_context, int, char *); EXPORT int xmp_smix_load_sample (xmp_context, int, char *);
#endif
EXPORT int xmp_smix_release_sample (xmp_context, int); EXPORT int xmp_smix_release_sample (xmp_context, int);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -415,6 +415,7 @@ int libxmp_scan_sequences (struct context_data *);
int libxmp_get_sequence (struct context_data *, int); int libxmp_get_sequence (struct context_data *, int);
int libxmp_set_player_mode (struct context_data *); int libxmp_set_player_mode (struct context_data *);
#ifdef EDUKE32_DISABLED
int8 read8s (FILE *, int *err); int8 read8s (FILE *, int *err);
uint8 read8 (FILE *, int *err); uint8 read8 (FILE *, int *err);
uint16 read16l (FILE *, int *err); uint16 read16l (FILE *, int *err);
@ -431,6 +432,7 @@ void write16b (FILE *, uint16);
void write32l (FILE *, uint32); void write32l (FILE *, uint32);
void write32b (FILE *, uint32); void write32b (FILE *, uint32);
int move_data (FILE *, FILE *, int); int move_data (FILE *, FILE *, int);
#endif
uint16 readmem16l (const uint8 *); uint16 readmem16l (const uint8 *);
uint16 readmem16b (const uint8 *); uint16 readmem16b (const uint8 *);

View file

@ -34,6 +34,7 @@
} while (0) } while (0)
#ifdef EDUKE32_DISABLED
uint8 read8(FILE *f, int *err) uint8 read8(FILE *f, int *err)
{ {
int a; int a;
@ -155,6 +156,7 @@ uint32 read32b(FILE *f, int *err)
set_error(ferror(f) ? errno : EOF); set_error(ferror(f) ? errno : EOF);
return 0xffffffff; return 0xffffffff;
} }
#endif
uint16 readmem16l(const uint8 *m) uint16 readmem16l(const uint8 *m)
{ {

View file

@ -28,6 +28,7 @@
#include "hio.h" #include "hio.h"
#include "mdataio.h" #include "mdataio.h"
#ifdef EDUKE32_DISABLED
static long get_size(FILE *f) static long get_size(FILE *f)
{ {
long size, pos; long size, pos;
@ -46,19 +47,24 @@ static long get_size(FILE *f)
return pos; return pos;
} }
} }
#endif
int8 hio_read8s(HIO_HANDLE *h) int8 hio_read8s(HIO_HANDLE *h)
{ {
#ifdef EDUKE32_DISABLED
int err; int err;
#endif
int8 ret = 0; int8 ret = 0;
switch (HIO_HANDLE_TYPE(h)) { switch (HIO_HANDLE_TYPE(h)) {
#ifdef EDUKE32_DISABLED
case HIO_HANDLE_TYPE_FILE: case HIO_HANDLE_TYPE_FILE:
ret = read8s(h->handle.file, &err); ret = read8s(h->handle.file, &err);
if (err != 0) { if (err != 0) {
h->error = err; h->error = err;
} }
break; break;
#endif
case HIO_HANDLE_TYPE_MEMORY: case HIO_HANDLE_TYPE_MEMORY:
ret = mread8s(h->handle.mem); ret = mread8s(h->handle.mem);
break; break;
@ -69,16 +75,20 @@ int8 hio_read8s(HIO_HANDLE *h)
uint8 hio_read8(HIO_HANDLE *h) uint8 hio_read8(HIO_HANDLE *h)
{ {
#ifdef EDUKE32_DISABLED
int err; int err;
#endif
uint8 ret = 0; uint8 ret = 0;
switch (HIO_HANDLE_TYPE(h)) { switch (HIO_HANDLE_TYPE(h)) {
#ifdef EDUKE32_DISABLED
case HIO_HANDLE_TYPE_FILE: case HIO_HANDLE_TYPE_FILE:
ret = read8(h->handle.file, &err); ret = read8(h->handle.file, &err);
if (err != 0) { if (err != 0) {
h->error = err; h->error = err;
} }
break; break;
#endif
case HIO_HANDLE_TYPE_MEMORY: case HIO_HANDLE_TYPE_MEMORY:
ret = mread8(h->handle.mem); ret = mread8(h->handle.mem);
break; break;
@ -89,16 +99,20 @@ uint8 hio_read8(HIO_HANDLE *h)
uint16 hio_read16l(HIO_HANDLE *h) uint16 hio_read16l(HIO_HANDLE *h)
{ {
#ifdef EDUKE32_DISABLED
int err; int err;
#endif
uint16 ret = 0; uint16 ret = 0;
switch (HIO_HANDLE_TYPE(h)) { switch (HIO_HANDLE_TYPE(h)) {
#ifdef EDUKE32_DISABLED
case HIO_HANDLE_TYPE_FILE: case HIO_HANDLE_TYPE_FILE:
ret = read16l(h->handle.file, &err); ret = read16l(h->handle.file, &err);
if (err != 0) { if (err != 0) {
h->error = err; h->error = err;
} }
break; break;
#endif
case HIO_HANDLE_TYPE_MEMORY: case HIO_HANDLE_TYPE_MEMORY:
ret = mread16l(h->handle.mem); ret = mread16l(h->handle.mem);
break; break;
@ -109,16 +123,20 @@ uint16 hio_read16l(HIO_HANDLE *h)
uint16 hio_read16b(HIO_HANDLE *h) uint16 hio_read16b(HIO_HANDLE *h)
{ {
#ifdef EDUKE32_DISABLED
int err; int err;
#endif
uint16 ret = 0; uint16 ret = 0;
switch (HIO_HANDLE_TYPE(h)) { switch (HIO_HANDLE_TYPE(h)) {
#ifdef EDUKE32_DISABLED
case HIO_HANDLE_TYPE_FILE: case HIO_HANDLE_TYPE_FILE:
ret = read16b(h->handle.file, &err); ret = read16b(h->handle.file, &err);
if (err != 0) { if (err != 0) {
h->error = err; h->error = err;
} }
break; break;
#endif
case HIO_HANDLE_TYPE_MEMORY: case HIO_HANDLE_TYPE_MEMORY:
ret = mread16b(h->handle.mem); ret = mread16b(h->handle.mem);
break; break;
@ -129,16 +147,20 @@ uint16 hio_read16b(HIO_HANDLE *h)
uint32 hio_read24l(HIO_HANDLE *h) uint32 hio_read24l(HIO_HANDLE *h)
{ {
#ifdef EDUKE32_DISABLED
int err; int err;
#endif
uint32 ret = 0; uint32 ret = 0;
switch (HIO_HANDLE_TYPE(h)) { switch (HIO_HANDLE_TYPE(h)) {
#ifdef EDUKE32_DISABLED
case HIO_HANDLE_TYPE_FILE: case HIO_HANDLE_TYPE_FILE:
ret = read24l(h->handle.file, &err); ret = read24l(h->handle.file, &err);
if (err != 0) { if (err != 0) {
h->error = err; h->error = err;
} }
break; break;
#endif
case HIO_HANDLE_TYPE_MEMORY: case HIO_HANDLE_TYPE_MEMORY:
ret = mread24l(h->handle.mem); ret = mread24l(h->handle.mem);
break; break;
@ -149,16 +171,20 @@ uint32 hio_read24l(HIO_HANDLE *h)
uint32 hio_read24b(HIO_HANDLE *h) uint32 hio_read24b(HIO_HANDLE *h)
{ {
#ifdef EDUKE32_DISABLED
int err; int err;
#endif
uint32 ret = 0; uint32 ret = 0;
switch (HIO_HANDLE_TYPE(h)) { switch (HIO_HANDLE_TYPE(h)) {
#ifdef EDUKE32_DISABLED
case HIO_HANDLE_TYPE_FILE: case HIO_HANDLE_TYPE_FILE:
ret = read24b(h->handle.file, &err); ret = read24b(h->handle.file, &err);
if (err != 0) { if (err != 0) {
h->error = err; h->error = err;
} }
break; break;
#endif
case HIO_HANDLE_TYPE_MEMORY: case HIO_HANDLE_TYPE_MEMORY:
ret = mread24b(h->handle.mem); ret = mread24b(h->handle.mem);
break; break;
@ -169,16 +195,20 @@ uint32 hio_read24b(HIO_HANDLE *h)
uint32 hio_read32l(HIO_HANDLE *h) uint32 hio_read32l(HIO_HANDLE *h)
{ {
#ifdef EDUKE32_DISABLED
int err; int err;
#endif
uint32 ret = 0; uint32 ret = 0;
switch (HIO_HANDLE_TYPE(h)) { switch (HIO_HANDLE_TYPE(h)) {
#ifdef EDUKE32_DISABLED
case HIO_HANDLE_TYPE_FILE: case HIO_HANDLE_TYPE_FILE:
ret = read32l(h->handle.file, &err); ret = read32l(h->handle.file, &err);
if (err != 0) { if (err != 0) {
h->error = err; h->error = err;
} }
break; break;
#endif
case HIO_HANDLE_TYPE_MEMORY: case HIO_HANDLE_TYPE_MEMORY:
ret = mread32l(h->handle.mem); ret = mread32l(h->handle.mem);
break; break;
@ -189,16 +219,20 @@ uint32 hio_read32l(HIO_HANDLE *h)
uint32 hio_read32b(HIO_HANDLE *h) uint32 hio_read32b(HIO_HANDLE *h)
{ {
#ifdef EDUKE32_DISABLED
int err; int err;
#endif
uint32 ret = 0; uint32 ret = 0;
switch (HIO_HANDLE_TYPE(h)) { switch (HIO_HANDLE_TYPE(h)) {
#ifdef EDUKE32_DISABLED
case HIO_HANDLE_TYPE_FILE: case HIO_HANDLE_TYPE_FILE:
ret = read32b(h->handle.file, &err); ret = read32b(h->handle.file, &err);
if (err != 0) { if (err != 0) {
h->error = err; h->error = err;
} }
break; break;
#endif
case HIO_HANDLE_TYPE_MEMORY: case HIO_HANDLE_TYPE_MEMORY:
ret = mread32b(h->handle.mem); 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; size_t ret = 0;
switch (HIO_HANDLE_TYPE(h)) { switch (HIO_HANDLE_TYPE(h)) {
#ifdef EDUKE32_DISABLED
case HIO_HANDLE_TYPE_FILE: case HIO_HANDLE_TYPE_FILE:
ret = fread(buf, size, num, h->handle.file); ret = fread(buf, size, num, h->handle.file);
if (ret != num) { if (ret != num) {
@ -221,6 +256,7 @@ size_t hio_read(void *buf, size_t size, size_t num, HIO_HANDLE *h)
} }
} }
break; break;
#endif
case HIO_HANDLE_TYPE_MEMORY: case HIO_HANDLE_TYPE_MEMORY:
ret = mread(buf, size, num, h->handle.mem); ret = mread(buf, size, num, h->handle.mem);
if (ret != num) { if (ret != num) {
@ -237,12 +273,14 @@ int hio_seek(HIO_HANDLE *h, long offset, int whence)
int ret = -1; int ret = -1;
switch (HIO_HANDLE_TYPE(h)) { switch (HIO_HANDLE_TYPE(h)) {
#ifdef EDUKE32_DISABLED
case HIO_HANDLE_TYPE_FILE: case HIO_HANDLE_TYPE_FILE:
ret = fseek(h->handle.file, offset, whence); ret = fseek(h->handle.file, offset, whence);
if (ret < 0) { if (ret < 0) {
h->error = errno; h->error = errno;
} }
break; break;
#endif
case HIO_HANDLE_TYPE_MEMORY: case HIO_HANDLE_TYPE_MEMORY:
ret = mseek(h->handle.mem, offset, whence); ret = mseek(h->handle.mem, offset, whence);
if (ret < 0) { if (ret < 0) {
@ -259,12 +297,14 @@ long hio_tell(HIO_HANDLE *h)
long ret = -1; long ret = -1;
switch (HIO_HANDLE_TYPE(h)) { switch (HIO_HANDLE_TYPE(h)) {
#ifdef EDUKE32_DISABLED
case HIO_HANDLE_TYPE_FILE: case HIO_HANDLE_TYPE_FILE:
ret = ftell(h->handle.file); ret = ftell(h->handle.file);
if (ret < 0) { if (ret < 0) {
h->error = errno; h->error = errno;
} }
break; break;
#endif
case HIO_HANDLE_TYPE_MEMORY: case HIO_HANDLE_TYPE_MEMORY:
ret = mtell(h->handle.mem); ret = mtell(h->handle.mem);
if (ret < 0) { if (ret < 0) {
@ -279,8 +319,10 @@ long hio_tell(HIO_HANDLE *h)
int hio_eof(HIO_HANDLE *h) int hio_eof(HIO_HANDLE *h)
{ {
switch (HIO_HANDLE_TYPE(h)) { switch (HIO_HANDLE_TYPE(h)) {
#ifdef EDUKE32_DISABLED
case HIO_HANDLE_TYPE_FILE: case HIO_HANDLE_TYPE_FILE:
return feof(h->handle.file); return feof(h->handle.file);
#endif
case HIO_HANDLE_TYPE_MEMORY: case HIO_HANDLE_TYPE_MEMORY:
return meof(h->handle.mem); return meof(h->handle.mem);
default: default:
@ -295,6 +337,7 @@ int hio_error(HIO_HANDLE *h)
return error; return error;
} }
#ifdef EDUKE32_DISABLED
HIO_HANDLE *hio_open(const void *path, const char *mode) HIO_HANDLE *hio_open(const void *path, const char *mode)
{ {
HIO_HANDLE *h; HIO_HANDLE *h;
@ -322,6 +365,7 @@ HIO_HANDLE *hio_open(const void *path, const char *mode)
err: err:
return NULL; return NULL;
} }
#endif
HIO_HANDLE *hio_open_mem(const void *ptr, long size) 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; return h;
} }
#ifdef EDUKE32_DISABLED
HIO_HANDLE *hio_open_file(FILE *f) HIO_HANDLE *hio_open_file(FILE *f)
{ {
HIO_HANDLE *h; HIO_HANDLE *h;
@ -354,15 +399,18 @@ HIO_HANDLE *hio_open_file(FILE *f)
return h; return h;
} }
#endif
int hio_close(HIO_HANDLE *h) int hio_close(HIO_HANDLE *h)
{ {
int ret; int ret;
switch (HIO_HANDLE_TYPE(h)) { switch (HIO_HANDLE_TYPE(h)) {
#ifdef EDUKE32_DISABLED
case HIO_HANDLE_TYPE_FILE: case HIO_HANDLE_TYPE_FILE:
ret = fclose(h->handle.file); ret = fclose(h->handle.file);
break; break;
#endif
case HIO_HANDLE_TYPE_MEMORY: case HIO_HANDLE_TYPE_MEMORY:
ret = mclose(h->handle.mem); ret = mclose(h->handle.mem);
break; break;

View file

@ -1,20 +1,26 @@
#ifndef XMP_HIO_H #ifndef XMP_HIO_H
#define XMP_HIO_H #define XMP_HIO_H
#ifdef EDUKE32_DISABLED
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#endif
#include <stddef.h> #include <stddef.h>
#include "memio.h" #include "memio.h"
#define HIO_HANDLE_TYPE(x) ((x)->type) #define HIO_HANDLE_TYPE(x) ((x)->type)
typedef struct { typedef struct {
#ifdef EDUKE32_DISABLED
#define HIO_HANDLE_TYPE_FILE 0 #define HIO_HANDLE_TYPE_FILE 0
#endif
#define HIO_HANDLE_TYPE_MEMORY 1 #define HIO_HANDLE_TYPE_MEMORY 1
int type; int type;
long size; long size;
union { union {
#ifdef EDUKE32_DISABLED
FILE *file; FILE *file;
#endif
MFILE *mem; MFILE *mem;
} handle; } handle;
int error; int error;
@ -33,9 +39,13 @@ int hio_seek (HIO_HANDLE *, long, int);
long hio_tell (HIO_HANDLE *); long hio_tell (HIO_HANDLE *);
int hio_eof (HIO_HANDLE *); int hio_eof (HIO_HANDLE *);
int hio_error (HIO_HANDLE *); int hio_error (HIO_HANDLE *);
#ifdef EDUKE32_DISABLED
HIO_HANDLE *hio_open (const void *, const char *); HIO_HANDLE *hio_open (const void *, const char *);
#endif
HIO_HANDLE *hio_open_mem (const void *, long); HIO_HANDLE *hio_open_mem (const void *, long);
#ifdef EDUKE32_DISABLED
HIO_HANDLE *hio_open_file (FILE *); HIO_HANDLE *hio_open_file (FILE *);
#endif
int hio_close (HIO_HANDLE *); int hio_close (HIO_HANDLE *);
long hio_size (HIO_HANDLE *); long hio_size (HIO_HANDLE *);

View file

@ -34,7 +34,9 @@
#include "format.h" #include "format.h"
#include "list.h" #include "list.h"
#include "hio.h" #include "hio.h"
#ifndef LIBXMP_CORE_PLAYER
#include "tempfile.h" #include "tempfile.h"
#endif
#ifndef LIBXMP_CORE_PLAYER #ifndef LIBXMP_CORE_PLAYER
#if !defined(HAVE_POPEN) && defined(WIN32) #if !defined(HAVE_POPEN) && defined(WIN32)
@ -282,6 +284,7 @@ static char *get_basename(char *name)
} }
#endif /* LIBXMP_CORE_PLAYER */ #endif /* LIBXMP_CORE_PLAYER */
#ifdef EDUKE32_DISABLED
int xmp_test_module(char *path, struct xmp_test_info *info) int xmp_test_module(char *path, struct xmp_test_info *info)
{ {
HIO_HANDLE *h; HIO_HANDLE *h;
@ -361,6 +364,7 @@ int xmp_test_module(char *path, struct xmp_test_info *info)
#endif #endif
return ret; return ret;
} }
#endif
static int load_module(xmp_context opaque, HIO_HANDLE *h) 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; return -XMP_ERROR_LOAD;
} }
#ifdef EDUKE32_DISABLED
int xmp_load_module(xmp_context opaque, char *path) int xmp_load_module(xmp_context opaque, char *path)
{ {
struct context_data *ctx = (struct context_data *)opaque; struct context_data *ctx = (struct context_data *)opaque;
@ -543,6 +548,7 @@ int xmp_load_module(xmp_context opaque, char *path)
return ret; return ret;
#endif #endif
} }
#endif
int xmp_load_module_from_memory(xmp_context opaque, void *mem, long size) 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; return ret;
} }
#ifdef EDUKE32_DISABLED
int xmp_load_module_from_file(xmp_context opaque, void *file, long size) int xmp_load_module_from_file(xmp_context opaque, void *file, long size)
{ {
struct context_data *ctx = (struct context_data *)opaque; 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; return ret;
} }
#endif
void xmp_release_module(xmp_context opaque) void xmp_release_module(xmp_context opaque)
{ {

View file

@ -172,6 +172,7 @@ int xmp_smix_channel_pan(xmp_context opaque, int chn, int pan)
return 0; return 0;
} }
#ifdef EDUKE32_DISABLED
int xmp_smix_load_sample(xmp_context opaque, int num, char *path) int xmp_smix_load_sample(xmp_context opaque, int num, char *path)
{ {
struct context_data *ctx = (struct context_data *)opaque; 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: err:
return retval; return retval;
} }
#endif
int xmp_smix_release_sample(xmp_context opaque, int num) int xmp_smix_release_sample(xmp_context opaque, int num)
{ {

View file

@ -1,7 +0,0 @@
#ifndef XMP_PLATFORM_H
#define XMP_PLATFORM_H
FILE *make_temp_file(char **);
void unlink_temp_file(char *);
#endif