Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSven Strickroth <email@cs-ware.de>2013-02-02 01:53:51 +0400
committerSven Strickroth <email@cs-ware.de>2013-02-02 03:55:32 +0400
commitc70455c75e30bf2a4cc5abdf4229d12d0e6cf159 (patch)
tree5f57f877e93e69f182336ad33ffa7b31c19baba0 /src/errors.c
parentbd25a302d3232dea375f226602fdcdb3a83abcdc (diff)
Deduplicate FormatMessage UTF-16 to UTF-8 conversion code
Signed-off-by: Sven Strickroth <email@cs-ware.de>
Diffstat (limited to 'src/errors.c')
-rw-r--r--src/errors.c33
1 files changed, 5 insertions, 28 deletions
diff --git a/src/errors.c b/src/errors.c
index 56f07b624..3aa1757b2 100644
--- a/src/errors.c
+++ b/src/errors.c
@@ -51,34 +51,11 @@ void giterr_set(int error_class, const char *string, ...)
if (error_class == GITERR_OS) {
#ifdef GIT_WIN32
- if (win32_error_code) {
- LPWSTR lpMsgBuf = NULL;
- int size = FormatMessageW(
- FORMAT_MESSAGE_ALLOCATE_BUFFER |
- FORMAT_MESSAGE_FROM_SYSTEM |
- FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, win32_error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPWSTR)&lpMsgBuf, 0, NULL);
-
- if (size) {
- int utf8_size = WideCharToMultiByte(CP_UTF8, 0, lpMsgBuf, -1, NULL, 0, NULL, NULL);
-
- char *lpMsgBuf_utf8 = git__malloc(utf8_size * sizeof(char));
- if (lpMsgBuf_utf8 == NULL) {
- LocalFree(lpMsgBuf);
- return;
- }
- if (!WideCharToMultiByte(CP_UTF8, 0, lpMsgBuf, -1, lpMsgBuf_utf8, utf8_size, NULL, NULL)) {
- LocalFree(lpMsgBuf);
- git__free(lpMsgBuf_utf8);
- return;
- }
-
- git_buf_PUTS(&buf, ": ");
- git_buf_puts(&buf, lpMsgBuf_utf8);
- LocalFree(lpMsgBuf);
- git__free(lpMsgBuf_utf8);
- }
+ char * win32_error = git_win32_get_error_message(win32_error_code);
+ if (win32_error) {
+ git_buf_PUTS(&buf, ": ");
+ git_buf_puts(&buf, win32_error);
+ git__free(win32_error);
SetLastError(0);
}