Skip to content

Commit

Permalink
Implement snprintf on win32 (#5533)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
RX14 committed Jan 4, 2018
1 parent 4648c1d commit b293b01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/lib_c/x86_64-windows-msvc/c/stdarg.cr
@@ -0,0 +1,3 @@
lib LibC
type VaList = Void*
end
9 changes: 8 additions & 1 deletion src/lib_c/x86_64-windows-msvc/c/stdio.cr
Expand Up @@ -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

0 comments on commit b293b01

Please sign in to comment.