]>
git.proxmox.com Git - libgit2.git/blob - src/win32/utf-conv.c
2 * Copyright (C) 2009-2012 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.
10 #include "git2/windows.h"
13 * Default codepage value
15 static int _active_codepage
= CP_UTF8
;
17 void gitwin_set_codepage(unsigned int codepage
)
19 _active_codepage
= codepage
;
22 unsigned int gitwin_get_codepage(void)
24 return _active_codepage
;
27 void gitwin_set_utf8(void)
29 _active_codepage
= CP_UTF8
;
32 wchar_t* gitwin_to_utf16(const char* str
)
41 cb
= strlen(str
) * sizeof(wchar_t);
43 ret
= (wchar_t*)git__malloc(sizeof(wchar_t));
48 /* Add space for null terminator */
49 cb
+= sizeof(wchar_t);
51 ret
= (wchar_t*)git__malloc(cb
);
53 if (MultiByteToWideChar(_active_codepage
, 0, str
, -1, ret
, cb
) == 0) {
61 int gitwin_append_utf16(wchar_t *buffer
, const char *str
, size_t len
)
63 return MultiByteToWideChar(_active_codepage
, 0, str
, -1, buffer
, len
);
66 char* gitwin_from_utf16(const wchar_t* str
)
75 cb
= wcslen(str
) * sizeof(char);
77 ret
= (char*)git__malloc(sizeof(char));
82 /* Add space for null terminator */
85 ret
= (char*)git__malloc(cb
);
87 if (WideCharToMultiByte(_active_codepage
, 0, str
, -1, ret
, cb
, NULL
, NULL
) == 0) {