From 303c9dfcbf8a4ed73fafd52d27fc1c2ec766bab4 Mon Sep 17 00:00:00 2001 From: RX14 Date: Thu, 4 Jan 2018 14:02:03 +0000 Subject: [PATCH] Implement snprintf on win32 x86_64-pc-windows-msvc doesn't export the snprintf symbol, only the vsnprintf symbol. This means we need to define out own snprintf implementation which captures va_args correctly. --- src/lib_c/x86_64-windows-msvc/c/stdarg.cr | 3 +++ src/lib_c/x86_64-windows-msvc/c/stdio.cr | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/lib_c/x86_64-windows-msvc/c/stdarg.cr diff --git a/src/lib_c/x86_64-windows-msvc/c/stdarg.cr b/src/lib_c/x86_64-windows-msvc/c/stdarg.cr new file mode 100644 index 000000000000..882d4f51d35c --- /dev/null +++ b/src/lib_c/x86_64-windows-msvc/c/stdarg.cr @@ -0,0 +1,3 @@ +lib LibC + type VaList = Void* +end diff --git a/src/lib_c/x86_64-windows-msvc/c/stdio.cr b/src/lib_c/x86_64-windows-msvc/c/stdio.cr index 3c6dfb7a60ef..b9c57ae4133e 100644 --- a/src/lib_c/x86_64-windows-msvc/c/stdio.cr +++ b/src/lib_c/x86_64-windows-msvc/c/stdio.cr @@ -3,5 +3,12 @@ require "./stddef" lib LibC fun printf(format : Char*, ...) : Int fun rename(old : Char*, new : Char*) : Int - fun snprintf(s : Char*, maxlen : SizeT, format : Char*, ...) : Int + fun vsnprintf(str : Char*, size : SizeT, format : Char*, ap : VaList) : Int + fun snprintf = __crystal_snprintf(str : Char*, size : SizeT, format : Char*, ...) : Int +end + +fun __crystal_snprintf(str : LibC::Char*, size : LibC::SizeT, format : LibC::Char*, ...) : LibC::Int + VaList.open do |varargs| + LibC.vsnprintf(str, size, format, varargs) + end end