Remove #define compat_h_macrodef__ and its absent case, which was only ever used for an old JFDuke3D port to PalmOS.

If for some reason you need to target a platform that lacks a libc, you're better off finding a libc, or putting together your own shim layer. It's a weekend project at most.

git-svn-id: https://svn.eduke32.com/eduke32@6070 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
hendricks266 2017-02-25 08:15:10 +00:00
parent 6d7191b848
commit ee4d69093c
2 changed files with 159 additions and 421 deletions

View file

@ -156,30 +156,22 @@
#include "libdivide.h"
// Define this to rewrite all 'B' versions to library functions. This
// is for platforms which give us a standard sort of C library so we
// link directly. Platforms like PalmOS which don't have a standard C
// library will need to wrap these functions with suitable emulations.
#define compat_h_macrodef__
#include <stdarg.h>
#include <stddef.h>
#ifdef compat_h_macrodef__
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <time.h>
# include <fcntl.h>
# include <ctype.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <errno.h>
# if defined(_WIN32)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#if defined(_WIN32)
# include <io.h>
# else
#else
# include <unistd.h>
# endif
#endif
#include <assert.h>
@ -505,68 +497,43 @@ FORCE_INLINE int32_t Blrintf(const float x)
# define FP_OFF(__p) ((uintptr_t)(__p))
#endif
#ifdef compat_h_macrodef__
# ifndef O_BINARY
#ifndef O_BINARY
# define O_BINARY 0
# endif
# ifndef O_TEXT
#endif
#ifndef O_TEXT
# define O_TEXT 0
# endif
#endif
# ifndef F_OK
#ifndef F_OK
# define F_OK 0
# endif
#endif
# define BO_BINARY O_BINARY
# define BO_TEXT O_TEXT
# define BO_RDONLY O_RDONLY
# define BO_WRONLY O_WRONLY
# define BO_RDWR O_RDWR
# define BO_APPEND O_APPEND
# define BO_CREAT O_CREAT
# define BO_TRUNC O_TRUNC
# define BS_IRGRP S_IRGRP
# define BS_IWGRP S_IWGRP
# define BS_IEXEC S_IEXEC
# ifdef __ANDROID__
#define BO_BINARY O_BINARY
#define BO_TEXT O_TEXT
#define BO_RDONLY O_RDONLY
#define BO_WRONLY O_WRONLY
#define BO_RDWR O_RDWR
#define BO_APPEND O_APPEND
#define BO_CREAT O_CREAT
#define BO_TRUNC O_TRUNC
#define BS_IRGRP S_IRGRP
#define BS_IWGRP S_IWGRP
#define BS_IEXEC S_IEXEC
#ifdef __ANDROID__
# define BS_IWRITE S_IWUSR
# define BS_IREAD S_IRUSR
# else
#else
# define BS_IWRITE S_IWRITE
# define BS_IREAD S_IREAD
# endif
# define BS_IFIFO S_IFIFO
# define BS_IFCHR S_IFCHR
# define BS_IFBLK S_IFBLK
# define BS_IFDIR S_IFDIR
# define BS_IFREG S_IFREG
# define BSEEK_SET SEEK_SET
# define BSEEK_CUR SEEK_CUR
# define BSEEK_END SEEK_END
#else
# define BO_BINARY 0
# define BO_TEXT 1
# define BO_RDONLY 2
# define BO_WRONLY 4
# define BO_RDWR 6
# define BO_APPEND 8
# define BO_CREAT 16
# define BO_TRUNC 32
# define BS_IRGRP 0
# define BS_IWGRP 0
# define BS_IEXEC 1
# define BS_IWRITE 2
# define BS_IREAD 4
# define BS_IFIFO 0x1000
# define BS_IFCHR 0x2000
# define BS_IFBLK 0x3000
# define BS_IFDIR 0x4000
# define BS_IFREG 0x8000
# define BSEEK_SET 0
# define BSEEK_CUR 1
# define BSEEK_END 2
#endif
#define BS_IFIFO S_IFIFO
#define BS_IFCHR S_IFCHR
#define BS_IFBLK S_IFBLK
#define BS_IFDIR S_IFDIR
#define BS_IFREG S_IFREG
#define BSEEK_SET SEEK_SET
#define BSEEK_CUR SEEK_CUR
#define BSEEK_END SEEK_END
#ifdef UNDERSCORES
# define ASMSYM(x) "_" x
@ -631,15 +598,9 @@ int32_t Bclosedir(BDIR *dir);
typedef intptr_t ssize_t;
#endif
#ifdef compat_h_macrodef__
typedef FILE BFILE;
# define bsize_t size_t
# define bssize_t ssize_t
#else
typedef void BFILE;
typedef uint32_t bsize_t;
typedef int32_t bssize_t;
#endif
typedef FILE BFILE;
typedef size_t bsize_t;
typedef ssize_t bssize_t;
typedef struct {
@ -681,174 +642,122 @@ FORCE_INLINE uint16_t system_15bit_rand(void) { return ((uint16_t)rand())&0x7fff
#endif
#if defined(_MSC_VER)
// XXX: non-__compat_h_macrodef__ version?
#define strtoll _strtoi64
#endif
#ifdef compat_h_macrodef__
# define Bassert assert
# define Brand rand
# define Balloca alloca
# define Bmalloc malloc
# define Bcalloc calloc
# define Brealloc realloc
# define Bfree free
# if defined(__cplusplus) && defined(_MSC_VER)
#define Bassert assert
#define Brand rand
#define Balloca alloca
#define Bmalloc malloc
#define Bcalloc calloc
#define Brealloc realloc
#define Bfree free
#if defined(__cplusplus) && defined(_MSC_VER)
# define Bstrdup _strdup
# define Bchdir _chdir
# define Bgetcwd _getcwd
# else
#else
# define Bstrdup strdup
# define Bchdir chdir
# define Bgetcwd getcwd
# endif
# define Bopen open
# define Bclose close
# define Bwrite write
# define Bread read
# define Blseek lseek
# if defined(__GNUC__)
#endif
#define Bopen open
#define Bclose close
#define Bwrite write
#define Bread read
#define Blseek lseek
#if defined(__GNUC__)
# define Btell(h) lseek(h,0,SEEK_CUR)
# else
#else
# define Btell tell
# endif
# ifdef _MSC_VER
#endif
#ifdef _MSC_VER
# define Bstat stat
# define Bfstat fstat
# else
#else
# define Bstat stat
# define Bfstat fstat
# endif
# define Bfileno fileno
# define Bferror ferror
# define Bfopen fopen
# define Bfclose fclose
# define Bfflush fflush
# define Bfeof feof
# define Bfgetc fgetc
# define Brewind rewind
# define Bfgets fgets
# define Bfputc fputc
# define Bfputs fputs
# define Bfread fread
# define Bfwrite fwrite
# define Bfprintf fprintf
# define Bfscanf fscanf
# define Bfseek fseek
# define Bftell ftell
# define Bputs puts
# define Bstrcpy strcpy
# define Bstrncpy strncpy
# define Bstrcmp strcmp
# define Bstrncmp strncmp
# if defined(_MSC_VER)
#endif
#define Bfileno fileno
#define Bferror ferror
#define Bfopen fopen
#define Bfclose fclose
#define Bfflush fflush
#define Bfeof feof
#define Bfgetc fgetc
#define Brewind rewind
#define Bfgets fgets
#define Bfputc fputc
#define Bfputs fputs
#define Bfread fread
#define Bfwrite fwrite
#define Bfprintf fprintf
#define Bfscanf fscanf
#define Bfseek fseek
#define Bftell ftell
#define Bputs puts
#define Bstrcpy strcpy
#define Bstrncpy strncpy
#define Bstrcmp strcmp
#define Bstrncmp strncmp
#if defined(_MSC_VER)
# define Bstrcasecmp _stricmp
# define Bstrncasecmp _strnicmp
# elif defined(__QNX__)
#elif defined(__QNX__)
# define Bstrcasecmp stricmp
# define Bstrncasecmp strnicmp
# else
#else
# define Bstrcasecmp strcasecmp
# define Bstrncasecmp strncasecmp
# endif
# if defined(_WIN32)
#endif
#if defined(_WIN32)
# define Bstrlwr strlwr
# define Bstrupr strupr
# define Bmkdir(s,x) mkdir(s)
# else
#else
# define Bmkdir mkdir
# endif
# define Bstrcat strcat
# define Bstrncat strncat
# define Bstrlen strlen
# define Bstrchr strchr
# define Bstrrchr strrchr
#endif
#define Bstrcat strcat
#define Bstrncat strncat
#define Bstrlen strlen
#define Bstrchr strchr
#define Bstrrchr strrchr
// XXX: different across 32- and 64-bit archs (e.g.
// parsing the decimal representation of 0xffffffff,
// 4294967295 -- long is signed, so strtol would
// return LONG_MAX (== 0x7fffffff on 32-bit archs))
# define Batoi(str) ((int32_t)strtol(str, NULL, 10))
# define Batol(str) (strtol(str, NULL, 10))
# define Batof(str) (strtod(str, NULL))
# define Bstrtol strtol
# define Bstrtoul strtoul
# define Bstrtod strtod
# define Bstrstr strstr
# define Bislower islower
# define Bisupper isupper
# define Bisdigit isdigit
# define Btoupper toupper
# define Btolower tolower
# define Bmemcpy memcpy
# define Bmemmove memmove
# define Bmemchr memchr
# define Bmemset memset
# define Bmemcmp memcmp
# define Bscanf scanf
# define Bprintf printf
# define Bsscanf sscanf
# define Bsprintf sprintf
# ifdef _MSC_VER
#define Batoi(str) ((int32_t)strtol(str, NULL, 10))
#define Batol(str) (strtol(str, NULL, 10))
#define Batof(str) (strtod(str, NULL))
#define Bstrtol strtol
#define Bstrtoul strtoul
#define Bstrtod strtod
#define Bstrstr strstr
#define Bislower islower
#define Bisupper isupper
#define Bisdigit isdigit
#define Btoupper toupper
#define Btolower tolower
#define Bmemcpy memcpy
#define Bmemmove memmove
#define Bmemchr memchr
#define Bmemset memset
#define Bmemcmp memcmp
#define Bscanf scanf
#define Bprintf printf
#define Bsscanf sscanf
#define Bsprintf sprintf
#ifdef _MSC_VER
# define Bsnprintf _snprintf
# define Bvsnprintf _vsnprintf
# else
#else
# define Bsnprintf snprintf
# define Bvsnprintf vsnprintf
# endif
# define Bvfprintf vfprintf
# define Bgetenv getenv
# define Btime() time(NULL)
# define Butime utime
#else
void Bassert(int);
int32_t Brand(void);
void *Bmalloc(bsize_t size);
void Bfree(void *ptr);
int32_t Bopen(const char *pathname, int32_t flags, unsigned mode);
int32_t Bclose(int32_t fd);
bssize_t Bwrite(int32_t fd, const void *buf, bsize_t count);
bssize_t Bread(int32_t fd, void *buf, bsize_t count);
int32_t Blseek(int32_t fildes, int32_t offset, int32_t whence);
BFILE *Bfopen(const char *path, const char *mode);
int32_t Bfclose(BFILE *stream);
int32_t Bfeof(BFILE *stream);
int32_t Bfgetc(BFILE *stream);
void Brewind(BFILE *stream);
char *Bfgets(char *s, int32_t size, BFILE *stream);
int32_t Bfputc(int32_t c, BFILE *stream);
int32_t Bfputs(const char *s, BFILE *stream);
bsize_t Bfread(void *ptr, bsize_t size, bsize_t nmemb, BFILE *stream);
bsize_t Bfwrite(const void *ptr, bsize_t size, bsize_t nmemb, BFILE *stream);
char *Bstrdup(const char *s);
char *Bstrcpy(char *dest, const char *src);
char *Bstrncpy(char *dest, const char *src, bsize_t n);
int32_t Bstrcmp(const char *s1, const char *s2);
int32_t Bstrncmp(const char *s1, const char *s2, bsize_t n);
int32_t Bstrcasecmp(const char *s1, const char *s2);
int32_t Bstrncasecmp(const char *s1, const char *s2, bsize_t n);
char *Bstrcat(char *dest, const char *src);
char *Bstrncat(char *dest, const char *src, bsize_t n);
bsize_t Bstrlen(const char *s);
char *Bstrchr(const char *s, int32_t c);
char *Bstrrchr(const char *s, int32_t c);
int32_t Batoi(const char *nptr);
int32_t Batol(const char *nptr);
int32_t Bstrtol(const char *nptr, char **endptr, int32_t base);
uint32_t Bstrtoul(const char *nptr, char **endptr, int32_t base);
void *Bmemcpy(void *dest, const void *src, bsize_t n);
void *Bmemmove(void *dest, const void *src, bsize_t n);
void *Bmemchr(const void *s, int32_t c, bsize_t n);
void *Bmemset(void *s, int32_t c, bsize_t n);
int32_t Bmemcmp(const void *s1, const void *s2, bsize_t n);
int32_t Bprintf(const char *format, ...) ATTRIBUTE((format(printf, 1, 2)));
int32_t Bsprintf(char *str, const char *format, ...) ATTRIBUTE((format(printf, 2, 3)));
int32_t Bsnprintf(char *str, bsize_t size, const char *format, ...) ATTRIBUTE((format(printf, 3, 4)));
int32_t Bvsnprintf(char *str, bsize_t size, const char *format, va_list ap);
char *Bgetcwd(char *buf, bsize_t size);
char *Bgetenv(const char *name);
#endif
#define Bvfprintf vfprintf
#define Bgetenv getenv
#define Btime() time(NULL)
#define Butime utime
char *Bgethomedir(void);
char *Bgetappdir(void);

View file

@ -1,15 +1,5 @@
/*
* Playing-field leveller for Build
* by Jonathon Fowler
*
* A note about this:
* 1. There is some kind of problem somewhere in the functions below because
* compiling with __compat_h_macrodef__ disabled makes stupid things happen.
* 2. The functions below, aside from the ones which aren't trivial, were never
* really intended to be used for anything except tracking anr removing ties
* to the standard C library from games. Using the Bxx versions of functions
* means we can redefine those names to link up with different runtime library
* names.
*/
#include "compat.h"
@ -76,167 +66,6 @@ void set_memerr_handler(void(*handlerfunc)(int32_t, const char *, const char *))
g_MemErrHandler = handlerfunc;
}
//////////
#ifndef compat_h_macrodef__
void Bassert(int expr) { assert(expr); }
int32_t Brand(void) { return rand(); }
void *Bmalloc(bsize_t size) { return malloc(size); }
void Bfree(void *ptr) { free(ptr); }
int32_t Bopen(const char *pathname, int32_t flags, uint32_t mode)
{
int32_t n = 0, o = 0;
if (flags & BO_BINARY)
n |= O_BINARY;
else
n |= O_TEXT;
if ((flags & BO_RDWR) == BO_RDWR)
n |= O_RDWR;
else if ((flags & BO_RDWR) == BO_WRONLY)
n |= O_WRONLY;
else if ((flags & BO_RDWR) == BO_RDONLY)
n |= O_RDONLY;
if (flags & BO_APPEND)
n |= O_APPEND;
if (flags & BO_CREAT)
n |= O_CREAT;
if (flags & BO_TRUNC)
n |= O_TRUNC;
if (mode & BS_IREAD)
o |= S_IREAD;
if (mode & BS_IWRITE)
o |= S_IWRITE;
if (mode & BS_IEXEC)
o |= S_IEXEC;
return open(pathname, n, o);
}
int32_t Bclose(int32_t fd) { return close(fd); }
bssize_t Bwrite(int32_t fd, const void *buf, bsize_t count) { return write(fd, buf, count); }
bssize_t Bread(int32_t fd, void *buf, bsize_t count) { return read(fd, buf, count); }
int32_t Blseek(int32_t fildes, int32_t offset, int32_t whence)
{
switch (whence)
{
case BSEEK_SET: whence = SEEK_SET; break;
case BSEEK_CUR: whence = SEEK_CUR; break;
case BSEEK_END: whence = SEEK_END; break;
}
return lseek(fildes, offset, whence);
}
BFILE *Bfopen(const char *path, const char *mode) { return (BFILE *)fopen(path, mode); }
int32_t Bfclose(BFILE *stream) { return fclose((FILE *)stream); }
void Brewind(BFILE *stream) { rewind((FILE *)stream); }
int32_t Bfgetc(BFILE *stream) { return fgetc((FILE *)stream); }
char *Bfgets(char *s, int32_t size, BFILE *stream) { return fgets(s, size, (FILE *)stream); }
int32_t Bfputc(int32_t c, BFILE *stream) { return fputc(c, (FILE *)stream); }
int32_t Bfputs(const char *s, BFILE *stream) { return fputs(s, (FILE *)stream); }
bsize_t Bfread(void *ptr, bsize_t size, bsize_t nmemb, BFILE *stream) { return fread(ptr, size, nmemb, (FILE *)stream); }
bsize_t Bfwrite(const void *ptr, bsize_t size, bsize_t nmemb, BFILE *stream) { return fwrite(ptr, size, nmemb, (FILE *)stream); }
char *Bstrdup(const char *s) { return strdup(s); }
char *Bstrcpy(char *dest, const char *src) { return strcpy(dest, src); }
char *Bstrncpy(char *dest, const char *src, bsize_t n) { return Bstrncpy(dest, src, n); }
int32_t Bstrcmp(const char *s1, const char *s2) { return strcmp(s1, s2); }
int32_t Bstrncmp(const char *s1, const char *s2, bsize_t n) { return strncmp(s1, s2, n); }
int32_t Bstrcasecmp(const char *s1, const char *s2)
{
#ifdef _MSC_VER
return _stricmp(s1, s2);
#else
return strcasecmp(s1, s2);
#endif
}
int32_t Bstrncasecmp(const char *s1, const char *s2, bsize_t n)
{
#ifdef _MSC_VER
return _strnicmp(s1, s2, n);
#else
return strncasecmp(s1, s2, n);
#endif
}
char *Bstrcat(char *dest, const char *src) { return strcat(dest, src); }
char *Bstrncat(char *dest, const char *src, bsize_t n) { return strncat(dest, src, n); }
bsize_t Bstrlen(const char *s) { return strlen(s); }
char *Bstrchr(const char *s, int32_t c) { return strchr(s, c); }
char *Bstrrchr(const char *s, int32_t c) { return strrchr(s, c); }
int32_t Batoi(const char *nptr) { return strtol(nptr, NULL, 10); }
int32_t Batol(const char *nptr) { return strtol(nptr, NULL, 10); }
int32_t Bstrtol(const char *nptr, char **endptr, int32_t base) { return strtol(nptr, endptr, base); }
uint32_t Bstrtoul(const char *nptr, char **endptr, int32_t base) { return strtoul(nptr, endptr, base); }
void *Bmemcpy(void *dest, const void *src, bsize_t n) { return memcpy(dest, src, n); }
void *Bmemmove(void *dest, const void *src, bsize_t n) { return memmove(dest, src, n); }
void *Bmemchr(const void *s, int32_t c, bsize_t n) { return memchr(s, c, n); }
void *Bmemset(void *s, int32_t c, bsize_t n) { return memset(s, c, n); }
int32_t Bprintf(const char *format, ...)
{
va_list ap;
int32_t r;
va_start(ap, format);
#ifdef _MSC_VER
r = _vprintf(format, ap);
#else
r = vprintf(format, ap);
#endif
va_end(ap);
return r;
}
int32_t Bsprintf(char *str, const char *format, ...)
{
va_list ap;
int32_t r;
va_start(ap, format);
#ifdef _MSC_VER
r = _vsprintf(str, format, ap);
#else
r = vsprintf(str, format, ap);
#endif
va_end(ap);
return r;
}
int32_t Bsnprintf(char *str, bsize_t size, const char *format, ...)
{
va_list ap;
int32_t r;
va_start(ap, format);
#ifdef _MSC_VER
r = _vsnprintf(str, size, format, ap);
#else
r = vsnprintf(str, size, format, ap);
#endif
va_end(ap);
return r;
}
int32_t Bvsnprintf(char *str, bsize_t size, const char *format, va_list ap)
{
#ifdef _MSC_VER
return _vsnprintf(str, size, format, ap);
#else
return vsnprintf(str, size, format, ap);
#endif
}
char *Bgetenv(const char *name) { return getenv(name); }
char *Bgetcwd(char *buf, bsize_t size) { return getcwd(buf, size); }
#endif // __compat_h_macrodef__
//
// Stuff which must be a function
//