aboutsummaryrefslogtreecommitdiffstats
path: root/localeinit.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-18 06:56:30 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-01-18 06:56:30 +0000
commit0ddcb9489ec40b8b59ec3026c245f2fe1b83e2c2 (patch)
tree94b91df43b8794e5b99ea2ebf2e616ae8401b628 /localeinit.c
parent254add068afd354c4be2f668d57fe71aa1d40866 (diff)
downloadruby-0ddcb9489ec40b8b59ec3026c245f2fe1b83e2c2.tar.gz
localeinit.c: codepage format
* localeinit.c (SIZEOF_CP_NAME, CP_FORMAT): extract to share codepage formatting code. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44635 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'localeinit.c')
-rw-r--r--localeinit.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/localeinit.c b/localeinit.c
index 369013fc26..420484a463 100644
--- a/localeinit.c
+++ b/localeinit.c
@@ -19,6 +19,11 @@
#include <langinfo.h>
#endif
+#if defined _WIN32
+#define SIZEOF_CP_NAME ((sizeof(UINT) * 8 / 3) + 4)
+#define CP_FORMAT(buf, codepage) snprintf(buf, sizeof(buf), "CP%u", (codepage))
+#endif
+
VALUE
rb_locale_charmap(VALUE klass)
{
@@ -26,7 +31,7 @@ rb_locale_charmap(VALUE klass)
# error NO_LOCALE_CHARMAP defined
#elif defined _WIN32 || defined __CYGWIN__
const char *codeset = 0;
- char cp[sizeof(int) * 3 + 4];
+ char cp[SIZEOF_CP_NAME];
# ifdef __CYGWIN__
const char *nl_langinfo_codeset(void);
codeset = nl_langinfo_codeset();
@@ -34,7 +39,7 @@ rb_locale_charmap(VALUE klass)
if (!codeset) {
UINT codepage = GetConsoleCP();
if (!codepage) codepage = GetACP();
- snprintf(cp, sizeof(cp), "CP%d", codepage);
+ CP_FORMAT(cp, codepage);
codeset = cp;
}
return rb_usascii_str_new2(codeset);
@@ -54,8 +59,8 @@ Init_enc_set_filesystem_encoding(void)
#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());
+ char cp[SIZEOF_CP_NAME];
+ CP_FORMAT(cp, AreFileApisANSI() ? GetACP() : GetOEMCP());
idx = rb_enc_find_index(cp);
if (idx < 0) idx = ENCINDEX_ASCII;
#else