|
VMS Help CRTL, iconv_open, Example *Conan The Librarian |
#include <stdio.h>
#include <iconv.h>
#include <errno.h>
int main()
{
/* Declare variables to be used */
char fromcodeset[30];
char tocodeset[30];
int iconv_opened;
iconv_t iconv_struct; /* Iconv descriptor */
/* Initialize variables */
sprintf(fromcodeset, "DECHANYU");
sprintf(tocodeset, "EUCTW");
iconv_opened = FALSE;
/* Attempt to create a conversion descriptor for the */
/* codesets specified. If the return value from */
/* iconv_open is -1 then an error has occurred. */
/* Check the value of errno. */
if ((iconv_struct = iconv_open(tocodeset, fromcodeset))
/* Check the value of errno */
switch (errno) {
case EMFILE:
case ENFILE:
printf("Too many iconv conversion files open\n");
break;
case ENOMEM:
printf("Not enough memory\n");
break;
case EINVAL:
printf("Unsupported conversion\n");
break;
default:
printf("Unexpected error from iconv_open\n");
break;
}
}
else
/* Successfully allocated a conversion descriptor */
iconv_opened = TRUE;
/* Was a conversion descriptor allocated */
if (iconv_opened) {
/* Attempt to deallocate the conversion descriptor. */
/* If iconv_close returns -1 then an error has */
/* occurred. */
if (iconv_close(iconv_struct) == -1) {
/* An error occurred. Check the value of errno */
switch (errno) {
case EBADF:
printf("Conversion descriptor is invalid\n");
break;
default:
printf("Unexpected error from iconv_close\n");
break;
}
}
}
return (EXIT_FAILURE);
}
|
|