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 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

View file

@ -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 *);

View file

@ -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)
{

View file

@ -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;

View file

@ -1,20 +1,26 @@
#ifndef XMP_HIO_H
#define XMP_HIO_H
#ifdef EDUKE32_DISABLED
#include <sys/types.h>
#include <sys/stat.h>
#endif
#include <stddef.h>
#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 *);

View file

@ -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)
{

View file

@ -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)
{

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