Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
8cc2f2d8
Commit
8cc2f2d8
authored
Mar 31, 2013
by
Philip Kelley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Win32 error reporting: Support WinHTTP errors
parent
0227fa2a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
16 deletions
+52
-16
src/win32/error.c
+52
-16
No files found.
src/win32/error.c
View file @
8cc2f2d8
...
@@ -8,34 +8,70 @@
...
@@ -8,34 +8,70 @@
#include "common.h"
#include "common.h"
#include "error.h"
#include "error.h"
#ifdef GIT_WINHTTP
# include <winhttp.h>
#endif
#define WC_ERR_INVALID_CHARS 0x80
char
*
git_win32_get_error_message
(
DWORD
error_code
)
char
*
git_win32_get_error_message
(
DWORD
error_code
)
{
{
LPWSTR
lpMsgBuf
=
NULL
;
LPWSTR
lpMsgBuf
=
NULL
;
HMODULE
hModule
=
NULL
;
char
*
utf8_msg
=
NULL
;
int
utf8_size
;
DWORD
dwFlags
=
FORMAT_MESSAGE_ALLOCATE_BUFFER
|
FORMAT_MESSAGE_IGNORE_INSERTS
;
if
(
!
error_code
)
if
(
!
error_code
)
return
NULL
;
return
NULL
;
if
(
FormatMessageW
(
#ifdef GIT_WINHTTP
FORMAT_MESSAGE_ALLOCATE_BUFFER
|
/* Errors raised by WinHTTP are not in the system resource table */
FORMAT_MESSAGE_FROM_SYSTEM
|
if
(
error_code
>=
WINHTTP_ERROR_BASE
&&
FORMAT_MESSAGE_IGNORE_INSERTS
,
error_code
<=
WINHTTP_ERROR_LAST
)
NULL
,
error_code
,
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
hModule
=
GetModuleHandleW
(
L"winhttp"
);
#endif
GIT_UNUSED
(
hModule
);
if
(
hModule
)
dwFlags
|=
FORMAT_MESSAGE_FROM_HMODULE
;
else
dwFlags
|=
FORMAT_MESSAGE_FROM_SYSTEM
;
if
(
FormatMessageW
(
dwFlags
,
hModule
,
error_code
,
MAKELANGID
(
LANG_NEUTRAL
,
SUBLANG_DEFAULT
),
(
LPWSTR
)
&
lpMsgBuf
,
0
,
NULL
))
{
(
LPWSTR
)
&
lpMsgBuf
,
0
,
NULL
))
{
int
utf8_size
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
lpMsgBuf
,
-
1
,
NULL
,
0
,
NULL
,
NULL
);
char
*
lpMsgBuf_utf8
=
git__malloc
(
utf8_size
*
sizeof
(
char
));
/* Invalid code point check supported on Vista+ only */
if
(
lpMsgBuf_utf8
==
NULL
)
{
if
(
LOBYTE
(
LOWORD
(
GetVersion
()))
>=
6
)
LocalFree
(
lpMsgBuf
);
dwFlags
=
WC_ERR_INVALID_CHARS
;
return
NULL
;
else
dwFlags
=
0
;
utf8_size
=
WideCharToMultiByte
(
CP_UTF8
,
dwFlags
,
lpMsgBuf
,
-
1
,
NULL
,
0
,
NULL
,
NULL
);
if
(
!
utf8_size
)
{
assert
(
0
);
goto
on_error
;
}
}
if
(
!
WideCharToMultiByte
(
CP_UTF8
,
0
,
lpMsgBuf
,
-
1
,
lpMsgBuf_utf8
,
utf8_size
,
NULL
,
NULL
))
{
LocalFree
(
lpMsgBuf
);
utf8_msg
=
git__malloc
(
utf8_size
);
git__free
(
lpMsgBuf_utf8
);
return
NULL
;
if
(
!
utf8_msg
)
goto
on_error
;
if
(
!
WideCharToMultiByte
(
CP_UTF8
,
dwFlags
,
lpMsgBuf
,
-
1
,
utf8_msg
,
utf8_size
,
NULL
,
NULL
))
{
git__free
(
utf8_msg
);
goto
on_error
;
}
}
on_error:
LocalFree
(
lpMsgBuf
);
LocalFree
(
lpMsgBuf
);
return
lpMsgBuf_utf8
;
}
}
return
NULL
;
return
utf8_msg
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment