From Lazarus wiki

The iconvenc package is a header file for the POSIX iconv posix library on Unix. Note that currently we try to keep this header portable, so GNUisms are not allowed. A simple Pascal wrapper to do a string conversion is also added.


While creating the header, some confusion arose over the fact that the library didn't always seem to write the last few chars. This turned out to be a buffering in the iconv lib, which isn't really spellled out in the man pages (though the below URLs do mention it cryptically).

The lib does autoflushed if the input string is 0 terminated (IOW if the count of chars to be passed is strlen(pchar)+1 or length(ansistring)+1), but an additional iconv(nil,nil,dest,outcharcount); will flush the buffer. (see the iconvert routine)


Thanks to Thomas Schatzl for his help solving the autoflushing issue, also thanks for Ido Kanner for helping with the testing setup, and Micha Nelissen and Ales Katona for minor help and testing.

linking method

The header file allows both dynamic as static linking, with static being the default. {$define loaddynamic} to make it try multiple libraries. A function to try additional library names is also provided.


The unit is called iconvenc because the main function already is named iconv.