Ruby 2.1.5p273(2014-11-13revision48405)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

localeinit.c
Go to the documentation of this file.
1 /**********************************************************************
2
3 localeinit.c -
4
5 $Author$
6 created at: Thu Jul 11 22:09:57 JST 2013
7
8 Copyright (C) 2013 Yukihiro Matsumoto
9
10 **********************************************************************/
11
12 #include "ruby/ruby.h"
13 #include "ruby/encoding.h"
14 #include "internal.h"
15 #ifdef __CYGWIN__
16 #include <windows.h>
17 #endif
18 #ifdef HAVE_LANGINFO_H
19 #include <langinfo.h>
20 #endif
21
22 VALUE
23 rb_locale_charmap(VALUE klass)
24 {
25 #if defined NO_LOCALE_CHARMAP
26 # error NO_LOCALE_CHARMAP defined
27 #elif defined _WIN32 || defined __CYGWIN__
28 const char *codeset = 0;
29 char cp[sizeof(int) * 3 + 4];
30 # ifdef __CYGWIN__
31 const char *nl_langinfo_codeset(void);
32 codeset = nl_langinfo_codeset();
33 # endif
34 if (!codeset) {
35 UINT codepage = GetConsoleCP();
36 if (!codepage) codepage = GetACP();
37 snprintf(cp, sizeof(cp), "CP%d", codepage);
38 codeset = cp;
39 }
40 return rb_usascii_str_new2(codeset);
41 #elif defined HAVE_LANGINFO_H
42 char *codeset;
43 codeset = nl_langinfo(CODESET);
44 return rb_usascii_str_new2(codeset);
45 #else
46 return Qnil;
47 #endif
48 }
49
50 int
51 Init_enc_set_filesystem_encoding(void)
52 {
53 int idx;
54 #if defined NO_LOCALE_CHARMAP
55 # error NO_LOCALE_CHARMAP defined
56 #elif defined _WIN32 || defined __CYGWIN__
57 char cp[sizeof(int) * 8 / 3 + 4];
58 snprintf(cp, sizeof cp, "CP%d", AreFileApisANSI() ? GetACP() : GetOEMCP());
59 idx = rb_enc_find_index(cp);
60 if (idx < 0) idx = ENCINDEX_ASCII;
61 #else
62 idx = rb_enc_to_index(rb_default_external_encoding());
63 #endif
64 return idx;
65 }
ruby.h
rb_usascii_str_new2
#define rb_usascii_str_new2
Definition: intern.h:846
nl_langinfo_codeset
const char * nl_langinfo_codeset(void)
Definition: langinfo.c:64
rb_default_external_encoding
rb_encoding * rb_default_external_encoding(void)
Definition: encoding.c:1351
snprintf
#define snprintf
Definition: subst.h:6
encoding.h
internal.h
Qnil
#define Qnil
Definition: ruby.h:427
VALUE
unsigned long VALUE
Definition: ruby.h:88
rb_locale_charmap
VALUE rb_locale_charmap(VALUE klass)
Definition: localeinit.c:23
Init_enc_set_filesystem_encoding
int Init_enc_set_filesystem_encoding(void)
Definition: localeinit.c:51
rb_enc_to_index
#define rb_enc_to_index(enc)
Definition: encoding.h:77
rb_enc_find_index
int rb_enc_find_index(const char *name)
Definition: encoding.c:684