[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mbstate_t



In glibc-2.1, mbstate_t is defined thus:

typedef struct
{
  int count;		/* Number of bytes needed for the current character. */
  wint_t value;		/* Value so far.  */
} mbstate_t;

Bruno is more thrifty in libutf8, defining it as:

typedef struct
{
  int dummy;    /* So that {0} is a valid constant initializer. */
} mbstate_t;

How is it defined in glibc-2.2?

If I define it in a private header file as follows, is there any
reason why my binary program shouldn't work with both libraries?

typedef struct
{
  union {
    struct {
      int count;
      wint_t value;
    } mbstate_t_glibc_2_1;
    struct
    {
      int dummy;    /* So that {0} is a valid constant initializer. */
    } mbstate_t_libutf8;
  } alternatives;
} mbstate_t;

If this works, is there something Bruno could put in his header file
libutf8.h to facilitate people building programs that are binary
compatible between glibc and libutf_plug.so?

You could detect at configure time whether the system headers define
mbstate_t. If they do, use:

#ifndef LIBUTF8_PLUG
#define mbstate_t utf8_mbstate_t
typedef struct
{
  int dummy;    /* So that {0} is a valid constant initializer. */
} mbstate_t;
#endif

If they don't use:

#if LIBUTF8_PLUG
typedef struct
{
  union {
#if WANT_GLIBC_COMPATIBILITY
    struct {
      int count;
      wint_t value;
    } glibc_2_1;
#endif
    struct
    {
      int dummy;
    } libutf8;
  } alternatives;
} mbstate_t;
#else
#define mbstate_t utf8_mbstate_t
typedef struct
{
  int dummy;    /* So that {0} is a valid constant initializer. */
} mbstate_t;
#endif

Would this work, and is it worth the trouble?

Edmund
-
Linux-UTF8:   i18n of Linux on all levels
Archive:      http://mail.nl.linux.org/lists/