summaryrefslogtreecommitdiff
path: root/localeinit.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-14 17:47:25 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-07-14 17:47:25 (GMT)
commit5f2080048e6bf76b647bec00c4b9cb1c7ec79ab2 (patch)
treeb8b5a58d3d573437a24f9a14158905713c93554e /localeinit.c
parent30486375713988a02c8463185e2b4613e042aaea (diff)
localeinit.c: split
* localeinit.c (rb_locale_charmap, Init_enc_set_filesystem_encoding): move from encoding.c. * miniinit.c (rb_locale_charmap, Init_enc_set_filesystem_encoding): define miniruby specific functions only. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41973 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'localeinit.c')
-rw-r--r--localeinit.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/localeinit.c b/localeinit.c
new file mode 100644
index 0000000..369013f
--- /dev/null
+++ b/localeinit.c
@@ -0,0 +1,65 @@
+/**********************************************************************
+
+ localeinit.c -
+
+ $Author$
+ created at: Thu Jul 11 22:09:57 JST 2013
+
+ Copyright (C) 2013 Yukihiro Matsumoto
+
+**********************************************************************/
+
+#include "ruby/ruby.h"
+#include "ruby/encoding.h"
+#include "internal.h"
+#ifdef __CYGWIN__
+#include <windows.h>
+#endif
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+
+VALUE
+rb_locale_charmap(VALUE klass)
+{
+#if defined NO_LOCALE_CHARMAP
+# error NO_LOCALE_CHARMAP defined
+#elif defined _WIN32 || defined __CYGWIN__
+ const char *codeset = 0;
+ char cp[sizeof(int) * 3 + 4];
+# ifdef __CYGWIN__
+ const char *nl_langinfo_codeset(void);
+ codeset = nl_langinfo_codeset();
+# endif
+ if (!codeset) {
+ UINT codepage = GetConsoleCP();
+ if (!codepage) codepage = GetACP();
+ snprintf(cp, sizeof(cp), "CP%d", codepage);
+ codeset = cp;
+ }
+ return rb_usascii_str_new2(codeset);
+#elif defined HAVE_LANGINFO_H
+ char *codeset;
+ codeset = nl_langinfo(CODESET);
+ return rb_usascii_str_new2(codeset);
+#else
+ return Qnil;
+#endif
+}
+
+int
+Init_enc_set_filesystem_encoding(void)
+{
+ int idx;
+#if defined NO_LOCALE_CHARMAP
+# error NO_LOCALE_CHARMAP defined
+#elif defined _WIN32 || defined __CYGWIN__
+ char cp[sizeof(int) * 8 / 3 + 4];
+ snprintf(cp, sizeof cp, "CP%d", AreFileApisANSI() ? GetACP() : GetOEMCP());
+ idx = rb_enc_find_index(cp);
+ if (idx < 0) idx = ENCINDEX_ASCII;
+#else
+ idx = rb_enc_to_index(rb_default_external_encoding());
+#endif
+ return idx;
+}