Page 1 of 1

iconv fuction in C-program returns EINVAL error

PostPosted: Tue Sep 21, 2010 10:09 pm
by kjesse
Hi!

I have compiled a C-program on z/os using the "iconv" function for UTF-8 to ASCII conversion. The program is compiled and linked to iconv. But when I run the program and invoke the iconv_open("IBM-367","UTF-8") I am getting an EINVAL error ("conversion is not supported"). The program runs also on Windows and Linux. What am I doing wrong with the parameters?

Regards

Klemens

Re: iconv fuction in C-program returns EINVAL error

PostPosted: Tue Sep 21, 2010 11:01 pm
by Robert Sample
Find a copy of the XL C/C++ Programming Guide manual and check appendix E Charmap files supplied with z/OS XL C/C++ and you will discover that IBM-367 is not a supplied conversion file, hence the message you got. When I use iconv to convert to / from ASCII, I use ISO8859-1 as the charmap.

Re: iconv fuction in C-program returns EINVAL error

PostPosted: Tue Sep 21, 2010 11:45 pm
by kjesse
Thank you for your hint. But I tried also to convert "UTF-8" to "IBM-273" (EBCDIC) and got the same error. I tried additionaly to add "//IGNORE//TRANSLIT" (as under Unix), but there returned the EINVAL error.

Re: iconv fuction in C-program returns EINVAL error

PostPosted: Wed Sep 22, 2010 3:03 am
by Robert Sample
All I can suggest is work with your site support group to determine what the problem is and how to fix it.

And you need to be aware that while z/OS Unix System Services looks like Unix, there are many ways it does not act like Unix. So the mere fact that "something" works under Unix has absolutely no meaning or correlation for Unix System Services -- the corresponding feature may work, may not work, or may require (possibly extensive) updating to make it work.

Re: iconv fuction in C-program returns EINVAL error

PostPosted: Wed Sep 22, 2010 1:12 pm
by kjesse
I have another question. How can I handle characters on z/os that cannot be converted? Does the program stop? Can I ignore or translit these characters? Under Unix I can say //IGNORE or //TRANSLIT as an option. Is this possible also with the mainframe?

Re: iconv fuction in C-program returns EINVAL error

PostPosted: Wed Sep 22, 2010 4:59 pm
by Robert Sample
If you do not have the IBM web site link for the XL C/C++ library bookmarked in your browser, I strongly suggest you do so -- NOW!. It is obvious that you need to spend several days reading the manuals in this library to understand the differences between z/OS C/C++ and whatever variant you are used to using. From the XL C/C++ Run-Time Library Reference manual, section 3.408 on iconv:
If a sequence of input bytes does not form a valid character in the specified encoded character set, conversion stops after the previous successfully converted character, and iconv() sets errno to EILSEQ. If the input buffer ends with an incomplete character or shift sequence, conversion stops after the previous successfully converted bytes, and iconv() sets errno to EINVAL. If the output buffer is not large enough to hold the entire converted input, conversion stops just before the input bytes that would cause the output buffer to overflow.

For just one example, you mentioned //TRANSLIT in your earlier post. There is not a single reference to TRANSLIT in either the XL C/C++ or Unix System Services bookshelves -- which is a pretty good sign that there's no such thing on the mainframe (at least in Unix System Services). The double forward slash is used for other purposes on the mainframe, so it would be extremely rare to see those characters used for a flag.