]>
git.proxmox.com Git - libgit2.git/blob - src/win32/utf-conv.c
2 * Copyright (C) 2009-2011 the libgit2 contributors
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
12 * Default codepage value
14 static int _active_codepage
= CP_UTF8
;
16 void gitwin_set_codepage(unsigned int codepage
)
18 _active_codepage
= codepage
;
21 unsigned int gitwin_get_codepage(void)
23 return _active_codepage
;
26 void gitwin_set_utf8(void)
28 _active_codepage
= CP_UTF8
;
31 wchar_t* gitwin_to_utf16(const char* str
)
40 cb
= strlen(str
) * sizeof(wchar_t);
42 ret
= (wchar_t*)git__malloc(sizeof(wchar_t));
47 /* Add space for null terminator */
48 cb
+= sizeof(wchar_t);
50 ret
= (wchar_t*)git__malloc(cb
);
52 if (MultiByteToWideChar(_active_codepage
, 0, str
, -1, ret
, cb
) == 0) {
60 char* gitwin_from_utf16(const wchar_t* str
)
69 cb
= wcslen(str
) * sizeof(char);
71 ret
= (char*)git__malloc(sizeof(char));
76 /* Add space for null terminator */
79 ret
= (char*)git__malloc(cb
);
81 if (WideCharToMultiByte(_active_codepage
, 0, str
, -1, ret
, cb
, NULL
, NULL
) == 0) {