From 3bb47bc1f5fc048e68168db5063fdcd2177a10e7 Mon Sep 17 00:00:00 2001 From: CNLohr Date: Tue, 14 Mar 2017 20:45:17 -0400 Subject: Update with the start of things to make TCC go in Windows. --- windows/tcc_stubs.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 windows/tcc_stubs.c (limited to 'windows/tcc_stubs.c') diff --git a/windows/tcc_stubs.c b/windows/tcc_stubs.c new file mode 100644 index 0000000..58cc8ed --- /dev/null +++ b/windows/tcc_stubs.c @@ -0,0 +1,59 @@ + +#include <_mingw.h> + +#define REMATH(x) double __cdecl x( double f ); float x##f(float v) { return x(v); } + +REMATH( acos ); +REMATH( cos ); +REMATH( sin ); +REMATH( sqrt ); +REMATH( asin ); + +double __cdecl strtod (const char* str, char** endptr); +float strtof( const char* str, char** endptr) +{ + return strtod( str, endptr ); +} + +double __cdecl atan2(double a, double b); +float atan2f(float a, float b) +{ + return atan2( a, b ); +} + +//From http://stackoverflow.com/questions/40159892/using-asprintf-on-windows +int __cdecl vsprintf_s( + char *buffer, + size_t numberOfElements, + const char *format, + va_list argptr +); + +int asprintf(char **strp, const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + int r = vasprintf(strp, fmt, ap); + va_end(ap); + return r; +} + +int vasprintf(char **strp, const char *fmt, va_list ap) { + // _vscprintf tells you how big the buffer needs to be + int len = _vscprintf(fmt, ap); + if (len == -1) { + return -1; + } + size_t size = (size_t)len + 1; + char *str = malloc(size); + if (!str) { + return -1; + } + // _vsprintf_s is the "secure" version of vsprintf + int r = vsprintf_s(str, len + 1, fmt, ap); + if (r == -1) { + free(str); + return -1; + } + *strp = str; + return r; +} \ No newline at end of file -- cgit v1.2.3 From e15459cd9efab607e95f720bd971d0e73615f437 Mon Sep 17 00:00:00 2001 From: CNLohr Date: Wed, 15 Mar 2017 00:14:37 -0400 Subject: Getting very close to a Windows port. --- windows/tcc_stubs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'windows/tcc_stubs.c') diff --git a/windows/tcc_stubs.c b/windows/tcc_stubs.c index 58cc8ed..7872914 100644 --- a/windows/tcc_stubs.c +++ b/windows/tcc_stubs.c @@ -44,7 +44,7 @@ int vasprintf(char **strp, const char *fmt, va_list ap) { return -1; } size_t size = (size_t)len + 1; - char *str = malloc(size); + char *str = (char*)malloc(size); if (!str) { return -1; } -- cgit v1.2.3