summaryrefslogtreecommitdiff
path: root/src/lib/evil/evil_locale.c
diff options
context:
space:
mode:
authorVincent Torri <vincent dot torri at gmail dot com>2015-11-27 18:43:54 +0100
committerTom Hacohen <tom@stosb.com>2015-11-30 16:28:02 +0000
commitcbb6e9b20f3d85b41b0c3c525fd3ae68864118b1 (patch)
treef7a2e3d3bcb1cda04613c280c8c5dd3fe0518c8a /src/lib/evil/evil_locale.c
parent21b1a3f221fb6bd477cfefbb9d0099717c13523d (diff)
Evil: add support for LC_MESSAGES for setlocale()
LC_MESSAGES is an extension to C ANSI and does not exist on Windows. So add LC_MESSAGES API and overload setlocale() to support it @feature
Diffstat (limited to 'src/lib/evil/evil_locale.c')
-rw-r--r--src/lib/evil/evil_locale.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/lib/evil/evil_locale.c b/src/lib/evil/evil_locale.c
new file mode 100644
index 0000000000..d243ad8b34
--- /dev/null
+++ b/src/lib/evil/evil_locale.c
@@ -0,0 +1,55 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <string.h>
6#include <locale.h>
7#include <errno.h>
8
9#ifndef WIN32_LEAN_AND_MEAN
10# define WIN32_LEAN_AND_MEAN
11#endif
12#include <windows.h>
13#undef WIN32_LEAN_AND_MEAN
14
15#include "evil_macro.h"
16#include "evil_locale.h"
17#include "evil_private.h"
18
19/*
20 * LOCALE_SISO639LANGNAME and LOCALE_SISO3166CTRYNAME need at least a buffer
21 * of 9 char each (including NULL char). So we need 2*8 + the trailing NULL
22 * char + '_', so 18 char.
23 */
24static char _evil_locale_buf[18];
25
26char *evil_setlocale(int category, const char *locale)
27{
28 char buf[9];
29 int l1;
30 int l2;
31
32 if (category != LC_MESSAGES)
33 return setlocale(category, locale);
34
35 if (locale != NULL)
36 {
37 errno = EINVAL;
38 return NULL;
39 }
40
41 l1 = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO639LANGNAME,
42 buf, sizeof(buf));
43 if (!l1) return NULL;
44
45 memcpy(_evil_locale_buf, buf, l1 - 1);
46 _evil_locale_buf[l1 - 1] = '_';
47
48 l2 = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO3166CTRYNAME,
49 buf, sizeof(buf));
50 if (!l2) return NULL;
51
52 memcpy(_evil_locale_buf + l1, buf, l2);
53
54 return _evil_locale_buf;
55}