Skip to content

Commit

Permalink
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/iconv.cr
Original file line number Diff line number Diff line change
@@ -8,10 +8,12 @@ struct Iconv
original_from, original_to = from, to

@skip_invalid = invalid == :skip
{% unless flag?(:freebsd) %}
if @skip_invalid
from = "#{from}//IGNORE"
to = "#{to}//IGNORE"
end
{% end %}

@iconv = LibC.iconv_open(to, from)

@@ -40,6 +42,11 @@ struct Iconv
end

def convert(inbuf : UInt8**, inbytesleft : LibC::SizeT*, outbuf : UInt8**, outbytesleft : LibC::SizeT*)
{% if flag?(:freebsd) %}
if @skip_invalid
return LibC.__iconv(@iconv, inbuf, inbytesleft, outbuf, outbytesleft, LibC::ICONV_F_HIDE_INVALID, out invalids)
end
{% end %}
LibC.iconv(@iconv, inbuf, inbytesleft, outbuf, outbytesleft)
end

3 changes: 3 additions & 0 deletions src/lib_c/x86_64-portbld-freebsd/c/iconv.cr
Original file line number Diff line number Diff line change
@@ -6,4 +6,7 @@ lib LibC
fun iconv(x0 : IconvT, x1 : Char**, x2 : SizeT*, x3 : Char**, x4 : SizeT*) : SizeT
fun iconv_close(x0 : IconvT) : Int
fun iconv_open(x0 : Char*, x1 : Char*) : IconvT

ICONV_F_HIDE_INVALID = 0x0001
fun __iconv(x0 : IconvT, x1 : Char**, x2 : SizeT*, x3 : Char**, x4 : SizeT*, flags : UInt32, invalids : SizeT*) : SizeT
end

0 comments on commit e1b98a5

Please sign in to comment.