Skip to content

Commit b293b01

Browse files
authoredJan 4, 2018
Implement snprintf on win32 (#5533)
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.
1 parent 4648c1d commit b293b01

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed
 

Diff for: ‎src/lib_c/x86_64-windows-msvc/c/stdarg.cr

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lib LibC
2+
type VaList = Void*
3+
end

Diff for: ‎src/lib_c/x86_64-windows-msvc/c/stdio.cr

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,12 @@ require "./stddef"
33
lib LibC
44
fun printf(format : Char*, ...) : Int
55
fun rename(old : Char*, new : Char*) : Int
6-
fun snprintf(s : Char*, maxlen : SizeT, format : Char*, ...) : Int
6+
fun vsnprintf(str : Char*, size : SizeT, format : Char*, ap : VaList) : Int
7+
fun snprintf = __crystal_snprintf(str : Char*, size : SizeT, format : Char*, ...) : Int
8+
end
9+
10+
fun __crystal_snprintf(str : LibC::Char*, size : LibC::SizeT, format : LibC::Char*, ...) : LibC::Int
11+
VaList.open do |varargs|
12+
LibC.vsnprintf(str, size, format, varargs)
13+
end
714
end

0 commit comments

Comments
 (0)