diff options
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | includes/BString.h | 4 | ||||
-rw-r--r-- | win32-vsscanf.c | 38 |
3 files changed, 43 insertions, 0 deletions
@@ -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 <string> #include <vector> +#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 <stdio.h> +#include <stdarg.h> +#include <malloc.h> +#include <string.h> + +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; +} |