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. --- win32-vsscanf.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 win32-vsscanf.c (limited to 'win32-vsscanf.c') 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