If the locale you request using setlocale is neither ‘C’ nor ‘POSIX’, the C library calls the function __user_find_locale to find a user-supplied locale. The standard implementation of this function is to return a null pointer which indicates that no additional locales are installed and, hence, no locale matches the request.

The prototype for __user_find_locale is:

const __RAL_locale_t *__user_find_locale(const char *locale);

The parameter locale is the locale to find and includes the code set. The locale name is identical to the name passed to setlocale when you select a locale.

Now let's install the Hungarian locale using both UTF-8 and ISO 8859-2 encodings. The UTF-8 codecs are included in the CrossWorks C library, but the Hungarian locale and the ISO 8859-2 codec are not.

You will find the file locale_hu_HU.c in the CrossWorks src directory along with the file codeset_iso_8859_2.c. Add these two files to your project.

Although this adds the data needed for the locales, it does not make these available for the C library: we need to write some code for __user_find_locale to return the appropriate locales.

To create the locales, we need to add the following code and data to tie everything together:

#include <__crossworks.h>

static const __RAL_locale_t hu_HU_utf8 = {
  &locale_hu_HU,
  &codeset_utf8
};

static const __RAL_locale_t hu_HU_iso_8859_2 = {
  &locale_hu_HU,
  &codeset_iso_8859_2
};

const __RAL_locale_t *
__user_find_locale(const char *locale)
{
  if (strncmp(locale, "hu_HU.utf8") == 0)
    return &hu_HU_utf8;
  else if (strncmp(locale, "hu_HU.iso_8859_2") == 0)
    return &hu_HU_iso_8859_2;
  else
    return 0;
}