aboutsummaryrefslogtreecommitdiffstats
path: root/localeinit.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-30 15:20:52 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-30 15:20:52 +0000
commit45ceb4b7cb42f57c08a72da6c7ec66ab62933c6f (patch)
tree0ada95de3a5d89a810469e9e0a82f4044506be4f /localeinit.c
parentbc23af5f88bbec0412072e537b91602e02d3084e (diff)
downloadruby-45ceb4b7cb42f57c08a72da6c7ec66ab62933c6f.tar.gz
localeinit.c: locale_charmap return value
* localeinit.c (locale_charmap): fix the return value to call conv function instead of encoding index on platforms where locale information is not available. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58221 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'localeinit.c')
-rw-r--r--localeinit.c35
1 files changed, 26 insertions, 9 deletions
diff --git a/localeinit.c b/localeinit.c
index eeec9adac6..394d8dc7d6 100644
--- a/localeinit.c
+++ b/localeinit.c
@@ -23,13 +23,20 @@
#define CP_FORMAT(buf, codepage) snprintf(buf, sizeof(buf), "CP%u", (codepage))
#endif
+#ifndef NO_LOCALE_CHARMAP
+# if defined _WIN32 || defined __CYGWIN__ || defined HAVE_LANGINFO_H
+# define NO_LOCALE_CHARMAP 0
+# else
+# define NO_LOCALE_CHARMAP 1
+# endif
+#endif
+
+#if !NO_LOCALE_CHARMAP
static VALUE
locale_charmap(VALUE (*conv)(const char *))
{
-#if defined NO_LOCALE_CHARMAP
-# error NO_LOCALE_CHARMAP defined
-#elif defined _WIN32 || defined __CYGWIN__
const char *codeset = 0;
+#if defined _WIN32 || defined __CYGWIN__
char cp[SIZEOF_CP_NAME];
# ifdef __CYGWIN__
const char *nl_langinfo_codeset(void);
@@ -41,15 +48,15 @@ locale_charmap(VALUE (*conv)(const char *))
CP_FORMAT(cp, codepage);
codeset = cp;
}
- return (*conv)(codeset);
#elif defined HAVE_LANGINFO_H
- char *codeset;
codeset = nl_langinfo(CODESET);
- return (*conv)(codeset);
+ ASSUME(codeset);
#else
- return ENCINDEX_US_ASCII;
+# error locale_charmap() is not implemented
#endif
+ return (*conv)(codeset);
}
+#endif
/*
* call-seq:
@@ -79,27 +86,37 @@ locale_charmap(VALUE (*conv)(const char *))
VALUE
rb_locale_charmap(VALUE klass)
{
+#if NO_LOCALE_CHARMAP
+ return rb_usascii_str_new_cstr("US-ASCII");
+#else
return locale_charmap(rb_usascii_str_new_cstr);
+#endif
}
+#if !NO_LOCALE_CHARMAP
static VALUE
enc_find_index(const char *name)
{
return (VALUE)rb_enc_find_index(name);
}
+#endif
int
rb_locale_charmap_index(void)
{
+#if NO_LOCALE_CHARMAP
+ return ENCINDEX_US_ASCII;
+#else
return (int)locale_charmap(enc_find_index);
+#endif
}
int
Init_enc_set_filesystem_encoding(void)
{
int idx;
-#if defined NO_LOCALE_CHARMAP
-# error NO_LOCALE_CHARMAP defined
+#if NO_LOCALE_CHARMAP
+ idx = ENCINDEX_US_ASCII;
#elif defined _WIN32
char cp[SIZEOF_CP_NAME];
CP_FORMAT(cp, AreFileApisANSI() ? GetACP() : GetOEMCP());