]>
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
)
40 cb
= strlen(str
) * sizeof(wchar_t);
42 return (wchar_t *)git__calloc(1, sizeof(wchar_t));
44 /* Add space for null terminator */
45 cb
+= sizeof(wchar_t);
47 ret
= (wchar_t *)git__malloc(cb
);
51 if (MultiByteToWideChar(_active_codepage
, 0, str
, -1, ret
, (int)cb
) == 0) {
52 giterr_set(GITERR_OS
, "Could not convert string to UTF-16");
60 int gitwin_append_utf16(wchar_t *buffer
, const char *str
, size_t len
)
62 int result
= MultiByteToWideChar(_active_codepage
, 0, str
, -1, buffer
, (int)len
);
64 giterr_set(GITERR_OS
, "Could not convert string to UTF-16");
68 char* gitwin_from_utf16(const wchar_t* str
)
76 cb
= wcslen(str
) * sizeof(char);
78 return (char *)git__calloc(1, sizeof(char));
80 /* Add space for null terminator */
83 ret
= (char*)git__malloc(cb
);
87 if (WideCharToMultiByte(_active_codepage
, 0, str
, -1, ret
, (int)cb
, NULL
, NULL
) == 0) {
88 giterr_set(GITERR_OS
, "Could not convert string to UTF-8");