From 78d9b284f1879725c071a348c0542c0ff31ab4da Mon Sep 17 00:00:00 2001 From: Nicolas 'Pixel' Noble Date: Sun, 20 Jan 2013 00:26:29 -0800 Subject: Tentatively adding vsscanf to win32 compilation. Untested tho. --- Makefile | 1 + includes/BString.h | 4 ++++ win32-vsscanf.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 win32-vsscanf.c diff --git a/Makefile b/Makefile index 6e6a888..eb30751 100644 --- a/Makefile +++ b/Makefile @@ -155,6 +155,7 @@ iconv.c \ localcharset.c \ relocatable.c \ msvc-regex.c \ +win32-vsscanf.c \ endif diff --git a/includes/BString.h b/includes/BString.h index f8f9710..f472d85 100644 --- a/includes/BString.h +++ b/includes/BString.h @@ -12,6 +12,10 @@ #include #include +#ifdef _WIN32 +int vsscanf(const char *, const char *, va_list); +#endif + namespace Balau { class String : private std::string { diff --git a/win32-vsscanf.c b/win32-vsscanf.c new file mode 100644 index 0000000..2391fb9 --- /dev/null +++ b/win32-vsscanf.c @@ -0,0 +1,38 @@ +#include +#include +#include +#include + +int vsscanf(const char * buffer, const char * format, va_list args) { + size_t count = 0; + const char * p = format; + char c; + while ((c = *p++)) + if ((c == '%') && ((p[0]) != '*' && (p[0] != '%'))) + count++; + + const char ** new_stack = (const char **) alloca((count + 2) * sizeof(void *)); + + new_stack[0] = buffer; + new_stack[1] = format; + memcpy(new_stack + 2, args, count * sizeof(const char *)); + + int r; + void * old_stack; + +#ifdef __x86_64__ +#error "Not written yet." +#else + asm ( + "mov %%esp, %0\n\t" + "mov %2, %%esp\n\t" + "call sscanf\n\t" + "mov %0, %%esp\n\t" + "mov %%eax, %1\n\t" + : "=r"(old_stack), "=r"(r) + : "r"(new_stack) + ); +#endif + + return r; +} -- cgit v1.2.3