Allocates a conversion descriptor for a specified codeset conversion.
#include <iconv.h> iconv_t iconv_open (const char *tocode, const char *fromcode);
x | A conversion descriptor. Indicates the call was successful. This descriptor is used in subsequent calls to iconv |
(iconv_t) -1 | Indicates an error occurred. The function sets errno to one of
the following:
|
#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 value of errno. */ /* */ if ((iconv_struct = iconv_open (tocodeset, fromcodeset)) == (iconv_t)-1) { /* */ /* 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(1); }