Iconv conversion issues with CRLF in C
Some network protocols such as http want line ends to be terminated with the traditional MS-DOS/Windows CRLF line wrap. When programming on OS/400 in C, communications to/from the outside world must additionally converted from EBDIC to ASCII and backwards with the standard C library iconv() function.
Using the default compiler settings in at least V4R5 converts the CR to ASCII 0x0d as to be expected, but converts a LF to 0x85[1] instead of 0x0a. Network packet dumps hence show the result as 0x0d 0x85, which is not the expected sequence.
Setting the compiler option sysifcopt(*ifsio) fixes this behavior.
Excerpt from the ILE C Programmer’s Guide, Chapter Text Streams and Binary Streams:
Note: The
*IFSIOoption also changes the value for the ’\n’ escape character value to the 0x25 line feed character. If*NOIFSIOis specified, the ’\n’ escape character has a value of 0x15.
Weblinks
- iconv() fails?, Narkive Newsgroup Archive
Footnotes
- ↑ The ASCII Next Line (NEL) control character.