Index: trunk/src/emx/ChangeLog.LIBC
===================================================================
--- trunk/src/emx/ChangeLog.LIBC	(revision 2057)
+++ trunk/src/emx/ChangeLog.LIBC	(revision 2058)
@@ -1,3 +1,8 @@
 /* $Id$ */
+
+2005-06-23: knut st. osmundsen <bird-gccos2-spam@anduin.net>
+    - libc:
+        o Fixed some more incorrectness of the 'C' locale, it only
+          defines the first 128 chars.
 
 2005-06-19: knut st. osmundsen <bird-gccos2-spam@anduin.net>
Index: trunk/src/emx/include/InnoTekLIBC/locale.h
===================================================================
--- trunk/src/emx/include/InnoTekLIBC/locale.h	(revision 2057)
+++ trunk/src/emx/include/InnoTekLIBC/locale.h	(revision 2058)
@@ -90,5 +90,5 @@
     /** MBCS prefixes. Two bits per character. */
     unsigned char           au2MBCSPrefixs[256/4];
-    /** Unicode translation. (0xffff means not translation.) */
+    /** Unicode translation. (0xffff means no translation.) */
     unsigned short          aucUnicode[256];
     /** Unicode -> SBCS conversion: 0..128. */
@@ -136,4 +136,8 @@
     /** Bit flags for every character (for iswXXX() function series). */
     unsigned        aufType[256];
+    /** Mask used to check if an index is within the above arrays.
+     * This is required because 'C' doesn't do more than 0-127. So,
+     * the mask is either ~0xff or ~0x7f. */
+    unsigned        uMask;
 } __LIBC_LOCALEWCTYPE;
 /** Pointer to the Ctype unicode struct. */
@@ -217,5 +221,5 @@
 extern const __LIBC_LOCALECTYPE     __libc_GLocaleCtypeDefault;
 /** Cached Unicode (__wchar_t) case conversion tables and flags. */
-extern const __LIBC_LOCALEWCTYPE    __libc_GLocaleWCtype;
+extern __LIBC_LOCALEWCTYPE    __libc_GLocaleWCtype;
 /** Locale information structure. */
 extern __LIBC_LOCALELCONV           __libc_gLocaleLconv;
Index: trunk/src/emx/include/_ctype.h
===================================================================
--- trunk/src/emx/include/_ctype.h	(revision 2057)
+++ trunk/src/emx/include/_ctype.h	(revision 2058)
@@ -71,4 +71,8 @@
     /** Bit flags for every character (for iswXXX() function series). */
     unsigned        aufType[256];
+    /** Mask used to check if an index is within the above arrays.
+     * This is required because 'C' doesn't do more than 0-127. So,
+     * the mask is either ~0xff or ~0x7f. */
+    unsigned        uMask;
 } __libc_GLocaleWCtype;
 __END_DECLS
@@ -160,73 +164,72 @@
  */
 __BEGIN_DECLS
-static inline unsigned __ctype(__ct_rune_t __ch, unsigned __f)
-{
-    return !((__ch) & ~0xffU)
-        ? __libc_GLocaleCtype.aufType[(__ch)/* & 0xff*/] & (__f)
+static __inline__ unsigned __ctype(__ct_rune_t __ch, unsigned __f)
+{
+    return !(__ch & ~0xffU)
+        ? __libc_GLocaleCtype.aufType[__ch] & __f
         : 0;
 }
 
-static inline int __istype(__ct_rune_t __ch, unsigned __f)
-{
-    return !!__ctype((__ch), (__f));
-}
-
-static inline int __isctype(__ct_rune_t __ch, unsigned __f)
-{
-    return !((__ch) & ~0xffU)
-        ? !!(__libc_GLocaleCtypeDefault.aufType[(__ch)/* & 0xff*/] & (__f))
+static __inline__ int __istype(__ct_rune_t __ch, unsigned __f)
+{
+    return !!__ctype(__ch, __f);
+}
+
+static __inline__ int __isctype(__ct_rune_t __ch, unsigned __f)
+{
+    return !(__ch & ~0xffU)
+        ? !!(__libc_GLocaleCtypeDefault.aufType[__ch] & __f)
         : 0;
 }
 
-static inline __ct_rune_t __toupper(__ct_rune_t __ch)
-{
-    return !((__ch) & ~0xffU)
-        ? __libc_GLocaleCtype.auchUpper[(__ch)/* & 0xff*/]
+static __inline__ __ct_rune_t __toupper(__ct_rune_t __ch)
+{
+    return !(__ch & ~0xffU)
+        ? __libc_GLocaleCtype.auchUpper[__ch]
         : (__ch);
 }
 
-static inline __ct_rune_t __tolower(__ct_rune_t __ch)
-{
-    return !((__ch) & ~0xffU)
-        ? __libc_GLocaleCtype.auchLower[(__ch)/* & 0xff*/]
-        : (__ch);
-}
-
-
-static inline unsigned __wctype(__wint_t __wc, unsigned __f)
-{
-    return !((__wc) & ~0xffU)
-        ? __libc_GLocaleWCtype.aufType[(__wc)] & (__f)
-        : ___wctype(__wc) & (__f);
-}
-
-static inline int __iswtype(__wint_t __wc, unsigned __f)
-{
-    return !!__wctype((__wc), (__f));
-}
-
-static inline __wint_t __towupper(__wint_t __wc)
-{
-    return !((__wc) & ~0xffU)
-        ? __libc_GLocaleWCtype.awcUpper[(__wc)]
+static __inline__ __ct_rune_t __tolower(__ct_rune_t __ch)
+{
+    return !(__ch & ~0xffU)
+        ? __libc_GLocaleCtype.auchLower[__ch]
+        : __ch;
+}
+
+
+static __inline__ unsigned __wctype(__wint_t __wc, unsigned __f)
+{
+    return !(__wc & __libc_GLocaleWCtype.uMask)
+        ? __libc_GLocaleWCtype.aufType[__wc] & __f
+        : ___wctype(__wc) & __f;
+}
+
+static __inline__ int __iswtype(__wint_t __wc, unsigned __f)
+{
+    return !!__wctype(__wc, __f);
+}
+
+static __inline__ __wint_t __towupper(__wint_t __wc)
+{
+    return !(__wc & __libc_GLocaleWCtype.uMask)
+        ? __libc_GLocaleWCtype.awcUpper[__wc]
         : ___towupper(__wc);
 }
 
-static inline __wint_t __towlower(__wint_t __wc)
-{
-    return !((__wc) & ~0xffU)
-        ? __libc_GLocaleWCtype.awcLower[(__wc)]
+static __inline__ __wint_t __towlower(__wint_t __wc)
+{
+    return !(__wc & __libc_GLocaleWCtype.uMask)
+        ? __libc_GLocaleWCtype.awcLower[__wc]
         : ___towlower(__wc);
 }
 
-
-static inline int __wcwidth(__wint_t __wc)
-{
-    if ((__wc) != 0)
+static __inline__ int __wcwidth(__wint_t __wc)
+{
+    if (__wc != 0)
     {
-        unsigned __f = __wctype((__wc), __CT_SCRW_MASK | __CT_PRINT);
-        return ((__f) & __CT_SCRW_MASK)
-            ? ((__f) & __CT_SCRW_MASK) >> __CT_SCRW_SHIFT
-            : ((__f) & __CT_PRINT) ? 1 : -1;
+        unsigned __f = __wctype(__wc, __CT_SCRW_MASK | __CT_PRINT);
+        return (__f & __CT_SCRW_MASK)
+            ? (__f & __CT_SCRW_MASK) >> __CT_SCRW_SHIFT
+            : (__f & __CT_PRINT) ? 1 : -1;
     }
     else
@@ -250,6 +253,6 @@
 unsigned    __wctype(__wint_t, unsigned);
 int         __iswtype(__wint_t, unsigned);
-__wint_t     __towupper(__wint_t);
-__wint_t     __towlower(__wint_t);
+__wint_t    __towupper(__wint_t);
+__wint_t    __towlower(__wint_t);
 int         __wcwidth(__wint_t);
 __END_DECLS
Index: trunk/src/emx/include/math.h
===================================================================
--- trunk/src/emx/include/math.h	(revision 2057)
+++ trunk/src/emx/include/math.h	(revision 2058)
@@ -97,4 +97,16 @@
     : (sizeof (x) == sizeof (double)) ? __isfinite(x)	\
     : __isfinitel(x))
+#ifdef IN_INNOTEK_LIBC
+#undef isinf
+#define	isinf(x)					\
+    ((sizeof (x) == sizeof (float)) ? __isinff(x)	\
+    : (sizeof (x) == sizeof (double)) ? _STD(isinf)(x)	\
+    : __isinfl(x))
+#undef isnan
+#define	isnan(x)					\
+    ((sizeof (x) == sizeof (float)) ? isnanf(x)		\
+    : (sizeof (x) == sizeof (double)) ? _STD(isnan)(x)	\
+    : __isnanl(x))
+#else
 #define	isinf(x)					\
     ((sizeof (x) == sizeof (float)) ? __isinff(x)	\
@@ -105,4 +117,5 @@
     : (sizeof (x) == sizeof (double)) ? isnan(x)	\
     : __isnanl(x))
+#endif
 #define	isnormal(x)					\
     ((sizeof (x) == sizeof (float)) ? __isnormalf(x)	\
@@ -234,6 +247,11 @@
 double	hypot(double, double);
 int	ilogb(double) __pure2;
+#ifdef IN_INNOTEK_LIBC
+int	_STD(isinf)(double) __pure2;
+int	_STD(isnan)(double) __pure2;
+#else
 int	(isinf)(double) __pure2;
 int	(isnan)(double) __pure2;
+#endif
 double	lgamma(double);
 long long llrint(double);
Index: trunk/src/emx/src/lib/bsd/locale/utf8.c
===================================================================
--- trunk/src/emx/src/lib/bsd/locale/utf8.c	(revision 2057)
+++ trunk/src/emx/src/lib/bsd/locale/utf8.c	(revision 2058)
@@ -71,5 +71,14 @@
 	return (0);
 }
-#endif /* !__INNOTEK_LIBC__ */
+#else
+void __libc_localeFuncsUTF8(__LIBC_PLOCALECTYPEFUNCS pFuncs)
+{
+    pFuncs->pfnmbsinit = _UTF8_mbsinit;
+    pFuncs->pfnmbrtowc = _UTF8_mbrtowc;
+    pFuncs->pfnmbsnrtowcs = _UTF8_mbsnrtowcs;
+    pFuncs->pfnwcrtomb = _UTF8_wcrtomb;
+    pFuncs->pfnwcsnrtombs = _UTF8_wcsnrtombs;
+}
+#endif /* __INNOTEK_LIBC__ */
 
 int
Index: trunk/src/emx/src/lib/locale/locale_ctype.c
===================================================================
--- trunk/src/emx/src/lib/locale/locale_ctype.c	(revision 2057)
+++ trunk/src/emx/src/lib/locale/locale_ctype.c	(revision 2058)
@@ -247,5 +247,5 @@
 
 /** Cached Unicode (__wchar_t) case conversion tables and flags. */
-const __LIBC_LOCALEWCTYPE    __libc_GLocaleWCtype =
+__LIBC_LOCALEWCTYPE    __libc_GLocaleWCtype =
 {
     .awcLower =
@@ -355,24 +355,24 @@
         0x000f0200, 0x000f0200, 0x000f0200, 0x000f0200, 0x000f0200, 0x000f0200, 0x000f0200, 0x000f0200,
     },
+    .uMask = ~0x7fU,
 };
 
 
-
 unsigned __wctype(__wint_t __wc, unsigned __f)
 {
-    return !((__wc) & ~0xffU)
-        ? __libc_GLocaleWCtype.aufType[(__wc)] & (__f)
-        : ___wctype(__wc) & (__f);
+    return !(__wc & __libc_GLocaleWCtype.uMask)
+        ? __libc_GLocaleWCtype.aufType[__wc] & __f
+        : ___wctype(__wc) & __f;
 }
 
 int __iswtype(__wint_t __wc, unsigned __f)
 {
-    return !!__wctype((__wc), (__f));
+    return !!__wctype(__wc, __f);
 }
 
 __wint_t __towupper(__wint_t __wc)
 {
-    return !((__wc) & ~0xffU)
-        ? __libc_GLocaleWCtype.awcUpper[(__wc)]
+    return !(__wc & __libc_GLocaleWCtype.uMask)
+        ? __libc_GLocaleWCtype.awcUpper[__wc]
         : ___towupper(__wc);
 }
@@ -380,21 +380,19 @@
 __wint_t __towlower(__wint_t __wc)
 {
-    return !((__wc) & ~0xffU)
-        ? __libc_GLocaleWCtype.awcLower[(__wc)]
+    return !(__wc & __libc_GLocaleWCtype.uMask)
+        ? __libc_GLocaleWCtype.awcLower[__wc]
         : ___towlower(__wc);
 }
 
-
 int __wcwidth(__wint_t __wc)
 {
-    if ((__wc) != 0)
-    {
-        unsigned __f = __wctype((__wc), __CT_SCRW_MASK | __CT_PRINT);
-        return ((__f) & __CT_SCRW_MASK)
-            ? ((__f) & __CT_SCRW_MASK) >> __CT_SCRW_SHIFT
-            : ((__f) & __CT_PRINT) ? 1 : -1;
-    }
-    else
-        return 0;
+    if (__wc != 0)
+    {
+        unsigned __f = __wctype(__wc, __CT_SCRW_MASK | __CT_PRINT);
+        return (__f & __CT_SCRW_MASK)
+            ? (__f & __CT_SCRW_MASK) >> __CT_SCRW_SHIFT
+            : (__f & __CT_PRINT) ? 1 : -1;
+    }
+    return 0;
 }
 
@@ -404,34 +402,38 @@
  * ASSUMES that none of the locals differs from the unicode spec
  */
-unsigned ___wctype(__wchar_t uc)
+unsigned ___wctype(__wchar_t wc)
 {
     unsigned    ufType = 0;
-    UNICTYPE   *pUniType = UniQueryCharType(uc);
-    if (pUniType)
-    {
-        /* ASSUMES CT_* << 8 == __* ! */
-        ufType = ((unsigned)pUniType->itype << 8)
-               & (__CT_UPPER  | __CT_LOWER  | __CT_DIGIT | __CT_SPACE |
-                  __CT_PUNCT  | __CT_CNTRL  | __CT_BLANK | __CT_XDIGIT |
-                  __CT_ALPHA  | __CT_ALNUM  | __CT_GRAPH | __CT_PRINT |
-                  __CT_NUMBER | __CT_SYMBOL | __CT_ASCII);
-        if (pUniType->extend & C3_IDEOGRAPH)
-            ufType |= __CT_IDEOGRAM;
-        if (ufType & (__CT_XDIGIT | __CT_DIGIT))
+    if (    __libc_GLocaleWCtype.uMask != ~0x7f
+        ||  wc <= 127)
+    {
+        UNICTYPE   *pUniType = UniQueryCharType(wc);
+        if (pUniType)
         {
-            if (     (unsigned)uc - 0x30U <= (0x39 - 0x30))
-                ufType |= (unsigned)uc - 0x30;
-            else if ((unsigned)uc - 0x41U <= (0x46 - 0x41))
-                ufType |= (unsigned)uc - 0x41 + 0xa;
-            else
+            /* ASSUMES CT_* << 8 == __* ! */
+            ufType = ((unsigned)pUniType->itype << 8)
+                   & (__CT_UPPER  | __CT_LOWER  | __CT_DIGIT | __CT_SPACE |
+                      __CT_PUNCT  | __CT_CNTRL  | __CT_BLANK | __CT_XDIGIT |
+                      __CT_ALPHA  | __CT_ALNUM  | __CT_GRAPH | __CT_PRINT |
+                      __CT_NUMBER | __CT_SYMBOL | __CT_ASCII);
+            if (pUniType->extend & C3_IDEOGRAPH)
+                ufType |= __CT_IDEOGRAM;
+            if (ufType & (__CT_XDIGIT | __CT_DIGIT))
             {
-                unsigned uVal = UniQueryNumericValue(uc);
-                if (!(uVal & ~0xffU))
-                    ufType |= uVal;
+                if (     (unsigned)wc - 0x30U <= (0x39 - 0x30))
+                    ufType |= (unsigned)wc - 0x30;
+                else if ((unsigned)wc - 0x41U <= (0x46 - 0x41))
+                    ufType |= (unsigned)wc - 0x41 + 0xa;
+                else
+                {
+                    unsigned uVal = UniQueryNumericValue(wc);
+                    if (!(uVal & ~0xffU))
+                        ufType |= uVal;
+                }
             }
+            ufType |= (pUniType->bidi & 0xf << 24);
+
+            /** @todo screen width. */
         }
-        ufType |= (pUniType->bidi & 0xf << 24);
-
-        /** @todo screen width. */
     }
     return ufType;
@@ -444,4 +446,7 @@
 __wchar_t ___towlower(__wchar_t wc)
 {
+    if (    __libc_GLocaleWCtype.uMask == ~0x7f
+        &&  wc > 127)
+        return wc;
     FS_VAR_SAVE_LOAD();
     UniChar ucRet = UniTolower(wc);
@@ -456,4 +461,7 @@
 __wchar_t ___towupper(__wchar_t wc)
 {
+    if (    __libc_GLocaleWCtype.uMask == ~0x7f
+        &&  wc > 127)
+        return wc;
     FS_VAR_SAVE_LOAD();
     UniChar ucRet = UniToupper(wc);
@@ -646,5 +654,6 @@
     }
     printf("\n"
-           "    },\n");
+           "    },\n"
+           "    .uMask = ~0x7f,\n");
 
     /* done */
Index: trunk/src/emx/src/lib/locale/mb_libuni.c
===================================================================
--- trunk/src/emx/src/lib/locale/mb_libuni.c	(revision 2057)
+++ trunk/src/emx/src/lib/locale/mb_libuni.c	(revision 2058)
@@ -93,13 +93,13 @@
         return ((size_t)-2);
 
-
     /*
      * Try the conversion table first.
      */
-    __wchar_t wc;
+    __wchar_t wc = -1;
     unsigned char uch = *(const unsigned char *)s;
-#ifndef NO_CONVERSION_TABLES
     if (    !pState->chState
-        &&  (wc = __libc_GLocaleCtype.aucUnicode[uch]) != 0xffff)
+        &&  (   (wc = __libc_GLocaleCtype.aucUnicode[uch]) != 0xffff
+             || !IS_MBCS_PREFIX(&__libc_GLocaleCtype, uch)))
+
     {
         if (pwc != NULL)
@@ -107,5 +107,9 @@
         return wc != 0;
     }
-#endif /* !NO_CONVERSION_TABLES */
+    if (!__libc_GLocaleCtype.uobj) /* no possible conversion */
+    {
+        errno = EILSEQ;
+        return ((size_t)-1);
+    }
 
     /*
@@ -120,11 +124,13 @@
     size_t  cIgnore = 0;
     uconv_attribute_t attr;
+    LOCALE_LOCK();
+    if (!__libc_GLocaleCtype.uobj)
+    {
+        LOCALE_UNLOCK();
+        errno = EILSEQ;
+        return ((size_t)-1);
+    }
     FS_VAR_SAVE_LOAD();
-    LOCALE_LOCK();
-    int rc = 0;
-    if (!__libc_GLocaleCtype.uobj)
-        rc = __libc_localeCreateObjects("C", NULL, NULL, &__libc_GLocaleCtype.lobj, &__libc_GLocaleCtype.uobj);
-    if (!rc)
-        rc = UniQueryUconvObject(__libc_GLocaleCtype.uobj, &attr, sizeof(attr), NULL, NULL, NULL);
+    int rc = UniQueryUconvObject(__libc_GLocaleCtype.uobj, &attr, sizeof(attr), NULL, NULL, NULL);
     if (!rc)
     {
@@ -140,4 +146,6 @@
                 ||  (rc == UCONV_E2BIG && !cwcOutLeft))
             {
+                if (wc == 0xfffd)
+                    wc = -1; /* this seems to make sense sometimes... */
                 if (pwc)
                     *pwc = wc;
@@ -177,5 +185,4 @@
      */
     char    ch;
-#ifndef NO_CONVERSION_TABLES
     if (!pState->chState)
     {
@@ -212,5 +219,9 @@
         /* not found */
     }
-#endif /* !NO_CONVERSION_TABLES */
+    if (!__libc_GLocaleCtype.uobj) /* no possible conversion */
+    {
+        errno = EILSEQ;
+        return ((size_t)-1);
+    }
 
     /*
@@ -224,13 +235,15 @@
     UniChar    *pucIn = &wc;
     uconv_attribute_t attr;
-    FS_VAR_SAVE_LOAD();
-    LOCALE_LOCK();
     size_t      cchMbCurMax = MB_CUR_MAX;
     size_t      cchOutLeft = cchMbCurMax;
-    int rc = 0;
+    LOCALE_LOCK();
     if (!__libc_GLocaleCtype.uobj)
-        rc = __libc_localeCreateObjects("C", NULL, NULL, &__libc_GLocaleCtype.lobj, &__libc_GLocaleCtype.uobj);
-    if (!rc)
-        rc = UniQueryUconvObject(__libc_GLocaleCtype.uobj, &attr, sizeof(attr), NULL, NULL, NULL);
+    {
+        LOCALE_UNLOCK();
+        errno = EILSEQ;
+        return ((size_t)-1);
+    }
+    FS_VAR_SAVE_LOAD();
+    int rc = UniQueryUconvObject(__libc_GLocaleCtype.uobj, &attr, sizeof(attr), NULL, NULL, NULL);
     if (!rc)
     {
@@ -453,8 +466,2 @@
 }
 
-/* later */
-void __libc_localeFuncsUTF8(__LIBC_PLOCALECTYPEFUNCS pFuncs)
-{
-    __libc_localeFuncsDefault(pFuncs);
-}
-
Index: trunk/src/emx/src/lib/locale/setlocale.c
===================================================================
--- trunk/src/emx/src/lib/locale/setlocale.c	(revision 2057)
+++ trunk/src/emx/src/lib/locale/setlocale.c	(revision 2058)
@@ -1299,5 +1299,5 @@
         case LC_CTYPE:
             rc = localeCtypeDo(&pTemp->Ctype, uobj, lobj, pszLocale, &szCodepageActual[0]);
-            fFree = rc != 0;
+            fFree = rc != 0 || IS_C_LOCALE(pszLocale) || IS_POSIX_LOCALE(pszLocale);
             break;
 
@@ -1538,4 +1538,9 @@
         memcpy(&__libc_GLocaleCtype, &pTemp->Ctype, sizeof(__libc_GLocaleCtype));
         MB_CUR_MAX = pTemp->Ctype.mbcs ? pTemp->Ctype.mbcs : 1;
+        if (    IS_C_LOCALE(pTemp->Global.apszNames[LC_CTYPE + 1])
+            ||  IS_POSIX_LOCALE(pTemp->Global.apszNames[LC_CTYPE + 1]))
+            __libc_GLocaleWCtype.uMask = ~0x7fU;
+        else
+            __libc_GLocaleWCtype.uMask = ~0xffU;
         pTemp->afProcessed[LC_CTYPE + 1] = 0;
         gLocale.apszNames[LC_CTYPE + 1] = pTemp->Global.apszNames[LC_CTYPE + 1];
