The ifx_gl_getmb() function

The ifx_gl_getmb() function obtains a single multibyte character from a user-specified location.

Syntax

#include <ifxgls.h>
...
int ifx_gl_fgetmb(mb, funcp, v, bytes_got)
       gl_mchar_t *mb;
       int (*funcp)(void *v);
       void *v;
       int *bytes_got;
mb
A pointer to the multibyte character whose bytes the funcp function reads from a specified location.
funcp
A pointer to a function that you define to specify the location from which to read the multibyte character.
v
A pointer that the ifx_gl_getmb() function passes to the funcp function each time that it is called.
bytes_got
A pointer to an integer that ifx_gl_getmb() sets to indicate the number of bytes that the funcp function has successfully read.
Valid in client application Valid in DataBlade® UDR
Yes Yes

Usage

The ifx_gl_getmb() function calls a function that you define to obtain the bytes that form one multibyte character from a specified location. This multibyte character is then written to the mb buffer.

The funcp argument is a pointer to a function that you must define as follows:
int funcp(void *v)

The pointer v is passed to funcp each time that it is called. On success, funcp must return a value 0 - 255, inclusive, which is the next byte of the multibyte character. On failure, funcp must return -1.

This function calls funcp until one of the following occurs:
  • A complete multibyte character has been formed.
  • The funcp function returns a byte that forms an illegal character when appended to the bytes already read.
  • The funcp function fails.
All bytes obtained by calling funcp are guaranteed to be written to mb. This function assumes that mb is large enough to hold the result. You can determine what will be written to mb in either of the following ways:
  • The function ifx_gl_mb_loc_max() calculates the maximum number of bytes in any multibyte character for the current locale.
  • The macro IFX_GL_MB_MAX is the maximum number of bytes in any multibyte character in any locale. This value is always equal to or greater than the value that ifx_gl_mb_loc_max() returns.

Of these two options, the macro IFX_GL_MB_MAX is faster, and it can be used to initialize static buffers. The function ifx_gl_mb_loc_max() is slower but more precise.

The number of bytes that funcp successfully reads is returned in bytes_got (even when funcp fails).

Return values

0 - 255
The value of the next byte for the multibyte character
-1
The function was not successful, and the error number is set to indicate the cause. See the Errors section.

Errors

If an error occurred, this function returns -1 and sets the ifx_gl_lc_errno() error number to one of the following values.
IFX_GL_EILSEQ
The bytes read from funcp do not form a valid multibyte character.
IFX_GL_EINVAL
The funcp function returned -1 in the middle of an otherwise valid multibyte character.
IFX_GL_EOF
The funcp function returned -1 on the first call.