diff options
Diffstat (limited to 'missing/langinfo.c')
| -rw-r--r-- | missing/langinfo.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/missing/langinfo.c b/missing/langinfo.c index a76000bc77..0274a378f5 100644 --- a/missing/langinfo.c +++ b/missing/langinfo.c @@ -32,11 +32,12 @@ * http://www.cl.cam.ac.uk/~mgk25/ucs/langinfo.c */ +#include "ruby/missing.h" #include <stdlib.h> #include <string.h> #if defined _WIN32 || defined __CYGWIN__ #include <windows.h> -#if defined _WIN32 +#if defined _WIN32 && !defined strncasecmp #define strncasecmp strnicmp #endif #endif @@ -55,7 +56,7 @@ #endif #define digit(x) ((x) >= '0' && (x) <= '9') -#define strstart(s, n) (strncasecmp(s, n, strlen(n)) == 0) +#define strstart(s, n) (strncasecmp((s), (n), strlen(n)) == 0) static char buf[16]; @@ -63,7 +64,8 @@ const char * nl_langinfo_codeset(void) { const char *l, *p; - + int n; + if (((l = getenv("LC_ALL")) && *l) || ((l = getenv("LC_CTYPE")) && *l) || ((l = getenv("LANG")) && *l)) { @@ -75,9 +77,9 @@ nl_langinfo_codeset(void) if (!p++) p = l; if (strstart(p, "UTF")) return "UTF-8"; - if (strstart(p, "8859-")) { - if (digit(p[5])) { - p += 5; + if ((n = 5, strstart(p, "8859-")) || (n = 9, strstart(p, "ISO-8859-"))) { + if (digit(p[n])) { + p += n; memcpy(buf, "ISO-8859-\0\0", 12); buf[9] = *p++; if (digit(*p)) buf[10] = *p++; @@ -138,7 +140,7 @@ char *nl_langinfo(nl_item item) #ifdef TEST #include <stdio.h> -int main() +int main(void) { printf("%s\n", nl_langinfo(CODESET)); return 0; |
