C – Is there an equivalent C function mbsinvalid on Linux?

Is there an equivalent C function mbsinvalid on Linux?… here is a solution to the problem.

Is there an equivalent C function mbsinvalid on Linux?

Porting C applications from AIX to Linux – Does anyone know if there is an equivalent mbsinvalid() function on Linux?

From the AIX page:

The mbsinvalid subroutine examines the string pointed to by the S parameter to determine the validity of the character. The LC_CTYPE category affects the behavior of the mbsinvalid subroutine. ”

http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf1/mbsinvalid.htm

Thanks!

Solution

Use mbstowcs with NULL destination pointers:

If dest is NULL, n is ignored, and the conversion proceeds as above, except that the converted wide characters are not written out to memory, and that no length limit exists.

….

  1. An invalid multibyte sequence has been encountered. In this case (size_t) -1 is returned.

(from mbstowcs man page).

That is, the result of (size_t)-1 means that there is an invalid multibyte sequence.

Related Problems and Solutions