VMS Help  —  CRTL  iconv_open
    Allocates a conversion descriptor for a specified codeset
    conversion.

    Format

      #include  <iconv.h>

      iconv_t iconv_open  (const char *tocode, const char *fromcode);

1  –  Arguments

 tocode

    The name of the codeset to which characters are converted.

 fromcode

    The name of the source codeset. See the "Developing International
    Software" chapter of the HP C RTL Reference Manual for
    information on obtaining a list of currently available codesets
    or for details on adding new codesets.

2  –  Return Values

    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:

                       o  EMFILE - The process does not have enough
                          I/O channels to open a file.

                       o  ENOMEM - Insufficient space is available.

                       o  EINVAL - The conversion specified by
                          fromcode and tocode is not supported.

                       o  EVMSERR - Nontranslatable OpenVMS error
                          occur. vaxc$errno contains the OpenVMS
                          error code. A value of SS$_BADCHKSUM in
                          vaxc$errno indicates that a conversion
                          table file was found, but its contents is
                          corrupted. A value of SS$_IDMISMATCH in
                          vaxc$errno indicates that the conversion
                          table file version does not match the
                          version of the C Run-Time Library.

3  –  Example

        #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);
        }
Close Help