00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "ruby/ruby.h"
00013 #include "ruby/encoding.h"
00014 #include "internal.h"
00015 #ifdef __CYGWIN__
00016 #include <windows.h>
00017 #endif
00018 #ifdef HAVE_LANGINFO_H
00019 #include <langinfo.h>
00020 #endif
00021
00022 VALUE
00023 rb_locale_charmap(VALUE klass)
00024 {
00025 #if defined NO_LOCALE_CHARMAP
00026 # error NO_LOCALE_CHARMAP defined
00027 #elif defined _WIN32 || defined __CYGWIN__
00028 const char *codeset = 0;
00029 char cp[sizeof(int) * 3 + 4];
00030 # ifdef __CYGWIN__
00031 const char *nl_langinfo_codeset(void);
00032 codeset = nl_langinfo_codeset();
00033 # endif
00034 if (!codeset) {
00035 UINT codepage = GetConsoleCP();
00036 if (!codepage) codepage = GetACP();
00037 snprintf(cp, sizeof(cp), "CP%d", codepage);
00038 codeset = cp;
00039 }
00040 return rb_usascii_str_new2(codeset);
00041 #elif defined HAVE_LANGINFO_H
00042 char *codeset;
00043 codeset = nl_langinfo(CODESET);
00044 return rb_usascii_str_new2(codeset);
00045 #else
00046 return Qnil;
00047 #endif
00048 }
00049
00050 int
00051 Init_enc_set_filesystem_encoding(void)
00052 {
00053 int idx;
00054 #if defined NO_LOCALE_CHARMAP
00055 # error NO_LOCALE_CHARMAP defined
00056 #elif defined _WIN32 || defined __CYGWIN__
00057 char cp[sizeof(int) * 8 / 3 + 4];
00058 snprintf(cp, sizeof cp, "CP%d", AreFileApisANSI() ? GetACP() : GetOEMCP());
00059 idx = rb_enc_find_index(cp);
00060 if (idx < 0) idx = ENCINDEX_ASCII;
00061 #else
00062 idx = rb_enc_to_index(rb_default_external_encoding());
00063 #endif
00064 return idx;
00065 }
00066