diff options
author | Nicolas 'Pixel' Noble <pixel@nobis-crew.org> | 2013-01-20 00:26:29 -0800 |
---|---|---|
committer | Nicolas 'Pixel' Noble <pixel@nobis-crew.org> | 2013-01-20 00:26:29 -0800 |
commit | 78d9b284f1879725c071a348c0542c0ff31ab4da (patch) | |
tree | fdf53804763f4a4ad69d4358ab9930177675d9a9 | |
parent | 71aba2fccba167f7c402f5f603e6f980b709b07e (diff) |
Tentatively adding vsscanf to win32 compilation. Untested tho.
-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; +} |