summaryrefslogtreecommitdiff
path: root/win32-vsscanf.c
diff options
context:
space:
mode:
authorNicolas 'Pixel' Noble <pixel@nobis-crew.org>2013-01-20 00:26:29 -0800
committerNicolas 'Pixel' Noble <pixel@nobis-crew.org>2013-01-20 00:26:29 -0800
commit78d9b284f1879725c071a348c0542c0ff31ab4da (patch)
treefdf53804763f4a4ad69d4358ab9930177675d9a9 /win32-vsscanf.c
parent71aba2fccba167f7c402f5f603e6f980b709b07e (diff)
Tentatively adding vsscanf to win32 compilation. Untested tho.
Diffstat (limited to 'win32-vsscanf.c')
-rw-r--r--win32-vsscanf.c38
1 files changed, 38 insertions, 0 deletions
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;
+}