Determine the number of bytes read and written

The ifx_gl_tomupper() and ifx_gl_tomlower() functions return an unsigned short integer that encodes the information about the number of bytes that the function has read.

The Informix® GLS library provides the following macros to obtain this information from the return value.
IFX_GL_CASE_CONV_SRC_BYTES()
The number of bytes read from the source string
IFX_GL_CASE_CONV_DST_BYTES()
The number of bytes written to the destination buffer
The following code fragment uses the ifx_gl_tomlower() function to convert a multibyte character to its lowercase equivalent. It uses the case-conversion macros to obtain the number of bytes read and written during the case-conversion operation:
/* Initialize source pointer, 'src_mb', to beginning of the
 * multibyte string. Initialize destination pointer to
 * beginning of destination buffer */
src_mb = src_mbs;
dst_mb = dst_mbs;

/* Traverse source string until the null terminator is
* reached */
while ( *src_mb != '\0' )
    {
/* Convert source multibyte character, 'src_mb', to lowercase
 * and put in the destination buffer */
    unsigned short retval =
        ifx_gl_tomlower(dst_mb, src_mb, src_mbs_bytes);
...
/* Increment the source pointer by the number of bytes that
 * have been read and the destination pointer by the number
 * of bytes that have been written */
    src_mb += IFX_GL_CASE_CONV_SRC_BYTES(retval);
    dst_mb += IFX_GL_CASE_CONV_DST_BYTES(retval);
    src_mbs_bytes -= IFX_GL_CASE_CONV_SRC_BYTES(retval);
    }
The memory-management rules for case conversion of a single multibyte character also apply to converting a string of one or more multibyte characters. For example, the following code fragment converts a multibyte-character string to its uppercase equivalent:
/* Assume src_mbs is null terminated */
src_mbs_bytes = strlen(src_mbs);
dst_mbs_bytes = ifx_gl_case_conv_outbuflen(src_mbs_bytes);

if ( dst_mbs_bytes == src_mbs_bytes )
    {
    /* If two strings have the same size, overwrite each
     * multibyte character in the 'src_mbs' multibyte string
     * with its uppercase equivalent */
    src_mb = src_mbs;
    while ( *src_mb != '\0' )
        {
        retval =
           ifx_gl_tomupper(src_mb,src_mb,IFX_GL_NO_LIMIT);
        src_mb += IFX_GL_CASE_CONV_SRC_BYTES(retval);
        }
    }
else
    {
    /* Two strings are not the same size, so must allocate a
     * destination buffer whose size is determined by the
     * ifx_gl_case_conv_outbuflen() function */
    dst_mbs = (gl_mchar_t *) malloc(dst_mbs_bytes + 1);

    src_mb = src_mbs;
    dst_mb = dst_mbs;

    while ( *src_mb != '\0' )
        {
        retval =
            ifx_gl_tomupper(dst_mb,src_mb,IFX_GL_NO_LIMIT);
        src_mb += IFX_GL_CASE_CONV_SRC_BYTES(retval);
        dst_mb += IFX_GL_CASE_CONV_DST_BYTES(retval);
        }

    *dst_mb = '\0';
    }

Copyright© 2019 HCL Technologies Limited