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
9c38f7a6
Commit
9c38f7a6
authored
Aug 07, 2013
by
Ben Straub
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add typedefs for win32 utf-8 and utf-16 buffers
...and normalize the signatures of the two conversion functions.
parent
75f98a95
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
62 additions
and
58 deletions
+62
-58
src/fileops.c
+2
-2
src/path.c
+2
-2
src/transports/winhttp.c
+4
-4
src/win32/dir.c
+4
-4
src/win32/findfile.c
+1
-1
src/win32/posix.h
+2
-2
src/win32/posix_w32.c
+28
-27
src/win32/utf-conv.c
+4
-4
src/win32/utf-conv.h
+5
-2
tests-clar/clar_libgit2.c
+10
-10
No files found.
src/fileops.c
View file @
9c38f7a6
...
...
@@ -58,9 +58,9 @@ int git_futils_creat_locked(const char *path, const mode_t mode)
int
fd
;
#ifdef GIT_WIN32
wchar_t
buf
[
GIT_WIN_PATH_UTF16
]
;
git_win_str_utf16
buf
;
git__utf8_to_16
(
buf
,
GIT_WIN_PATH_UTF16
,
path
);
git__utf8_to_16
(
buf
,
path
);
fd
=
_wopen
(
buf
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
|
O_EXCL
|
O_BINARY
|
O_CLOEXEC
,
mode
);
#else
...
...
src/path.c
View file @
9c38f7a6
...
...
@@ -486,14 +486,14 @@ bool git_path_is_empty_dir(const char *path)
{
git_buf
pathbuf
=
GIT_BUF_INIT
;
HANDLE
hFind
=
INVALID_HANDLE_VALUE
;
wchar_t
wbuf
[
GIT_WIN_PATH_UTF16
]
;
git_win_str_utf16
wbuf
;
WIN32_FIND_DATAW
ffd
;
bool
retval
=
true
;
if
(
!
git_path_isdir
(
path
))
return
false
;
git_buf_printf
(
&
pathbuf
,
"%s
\\
*"
,
path
);
git__utf8_to_16
(
wbuf
,
GIT_WIN_PATH_UTF16
,
git_buf_cstr
(
&
pathbuf
));
git__utf8_to_16
(
wbuf
,
git_buf_cstr
(
&
pathbuf
));
hFind
=
FindFirstFileW
(
wbuf
,
&
ffd
);
if
(
INVALID_HANDLE_VALUE
==
hFind
)
{
...
...
src/transports/winhttp.c
View file @
9c38f7a6
...
...
@@ -264,7 +264,7 @@ static int winhttp_stream_connect(winhttp_stream *s)
if
(
git_buf_printf
(
&
buf
,
"Content-Type: application/x-git-%s-request"
,
s
->
service
)
<
0
)
goto
on_error
;
git__utf8_to_16
(
ct
,
MAX_CONTENT_TYPE_LEN
,
git_buf_cstr
(
&
buf
));
git__utf8_to_16
(
ct
,
git_buf_cstr
(
&
buf
));
if
(
!
WinHttpAddRequestHeaders
(
s
->
request
,
ct
,
(
ULONG
)
-
1L
,
WINHTTP_ADDREQ_FLAG_ADD
))
{
giterr_set
(
GITERR_OS
,
"Failed to add a header to the request"
);
...
...
@@ -593,7 +593,7 @@ replay:
else
snprintf
(
expected_content_type_8
,
MAX_CONTENT_TYPE_LEN
,
"application/x-git-%s-advertisement"
,
s
->
service
);
git__utf8_to_16
(
expected_content_type
,
MAX_CONTENT_TYPE_LEN
,
expected_content_type_8
);
git__utf8_to_16
(
expected_content_type
,
expected_content_type_8
);
content_type_length
=
sizeof
(
content_type
);
if
(
!
WinHttpQueryHeaders
(
s
->
request
,
...
...
@@ -893,7 +893,7 @@ static int winhttp_connect(
const
char
*
url
)
{
wchar_t
*
ua
=
L"git/1.0 (libgit2 "
WIDEN
(
LIBGIT2_VERSION
)
L")"
;
wchar_t
host
[
GIT_WIN_PATH_UTF16
]
;
git_win_str_utf16
host
;
int32_t
port
;
const
char
*
default_port
=
"80"
;
int
ret
;
...
...
@@ -920,7 +920,7 @@ static int winhttp_connect(
return
-
1
;
/* Prepare host */
git__utf8_to_16
(
host
,
GIT_WIN_PATH_UTF16
,
t
->
host
);
git__utf8_to_16
(
host
,
t
->
host
);
/* Establish session */
t
->
session
=
WinHttpOpen
(
...
...
src/win32/dir.c
View file @
9c38f7a6
...
...
@@ -26,7 +26,7 @@ static int init_filter(char *filter, size_t n, const char *dir)
git__DIR
*
git__opendir
(
const
char
*
dir
)
{
char
filter
[
GIT_WIN_PATH_UTF8
];
wchar_t
filter_w
[
GIT_WIN_PATH_UTF16
]
;
git_win_str_utf16
filter_w
;
git__DIR
*
new
=
NULL
;
if
(
!
dir
||
!
init_filter
(
filter
,
sizeof
(
filter
),
dir
))
...
...
@@ -40,7 +40,7 @@ git__DIR *git__opendir(const char *dir)
if
(
!
new
->
dir
)
goto
fail
;
git__utf8_to_16
(
filter_w
,
GIT_WIN_PATH_UTF16
,
filter
);
git__utf8_to_16
(
filter_w
,
filter
);
new
->
h
=
FindFirstFileW
(
filter_w
,
&
new
->
f
);
if
(
new
->
h
==
INVALID_HANDLE_VALUE
)
{
...
...
@@ -102,7 +102,7 @@ struct git__dirent *git__readdir(git__DIR *d)
void
git__rewinddir
(
git__DIR
*
d
)
{
char
filter
[
GIT_WIN_PATH_UTF8
];
wchar_t
filter_w
[
GIT_WIN_PATH_UTF16
]
;
git_win_str_utf16
filter_w
;
if
(
!
d
)
return
;
...
...
@@ -116,7 +116,7 @@ void git__rewinddir(git__DIR *d)
if
(
!
init_filter
(
filter
,
sizeof
(
filter
),
d
->
dir
))
return
;
git__utf8_to_16
(
filter_w
,
GIT_WIN_PATH_UTF16
,
filter
);
git__utf8_to_16
(
filter_w
,
filter
);
d
->
h
=
FindFirstFileW
(
filter_w
,
&
d
->
f
);
if
(
d
->
h
==
INVALID_HANDLE_VALUE
)
...
...
src/win32/findfile.c
View file @
9c38f7a6
...
...
@@ -53,7 +53,7 @@ int git_win32__find_file(
if
(
*
filename
==
'/'
||
*
filename
==
'\\'
)
filename
++
;
git__utf8_to_16
(
file_utf16
+
root
->
len
-
1
,
alloc_len
,
filename
);
git__utf8_to_16
(
file_utf16
+
root
->
len
-
1
,
filename
);
/* check access */
if
(
_waccess
(
file_utf16
,
F_OK
)
<
0
)
{
...
...
src/win32/posix.h
View file @
9c38f7a6
...
...
@@ -20,9 +20,9 @@ GIT_INLINE(int) p_link(const char *old, const char *new)
GIT_INLINE
(
int
)
p_mkdir
(
const
char
*
path
,
mode_t
mode
)
{
wchar_t
buf
[
GIT_WIN_PATH_UTF16
]
;
git_win_str_utf16
buf
;
GIT_UNUSED
(
mode
);
git__utf8_to_16
(
buf
,
GIT_WIN_PATH_UTF16
,
path
);
git__utf8_to_16
(
buf
,
path
);
return
_wmkdir
(
buf
);
}
...
...
src/win32/posix_w32.c
View file @
9c38f7a6
...
...
@@ -16,8 +16,8 @@
int
p_unlink
(
const
char
*
path
)
{
wchar_t
buf
[
GIT_WIN_PATH_UTF16
]
;
git__utf8_to_16
(
buf
,
GIT_WIN_PATH_UTF16
,
path
);
git_win_str_utf16
buf
;
git__utf8_to_16
(
buf
,
path
);
_wchmod
(
buf
,
0666
);
return
_wunlink
(
buf
);
}
...
...
@@ -59,10 +59,11 @@ static int do_lstat(
const
char
*
file_name
,
struct
stat
*
buf
,
int
posix_enotdir
)
{
WIN32_FILE_ATTRIBUTE_DATA
fdata
;
wchar_t
fbuf
[
GIT_WIN_PATH_UTF16
],
lastch
;
git_win_str_utf16
fbuf
;
wchar_t
lastch
;
int
flen
;
flen
=
git__utf8_to_16
(
fbuf
,
GIT_WIN_PATH_UTF16
,
file_name
);
flen
=
git__utf8_to_16
(
fbuf
,
file_name
);
/* truncate trailing slashes */
for
(;
flen
>
0
;
--
flen
)
{
...
...
@@ -165,7 +166,7 @@ int p_readlink(const char *link, char *target, size_t target_len)
static
fpath_func
pGetFinalPath
=
NULL
;
HANDLE
hFile
;
DWORD
dwRet
;
wchar_t
link_w
[
GIT_WIN_PATH_UTF16
]
;
git_win_str_utf16
link_w
;
wchar_t
*
target_w
;
int
error
=
0
;
...
...
@@ -188,7 +189,7 @@ int p_readlink(const char *link, char *target, size_t target_len)
}
}
git__utf8_to_16
(
link_w
,
GIT_WIN_PATH_UTF16
,
link
);
git__utf8_to_16
(
link_w
,
link
);
hFile
=
CreateFileW
(
link_w
,
// file to open
GENERIC_READ
,
// open for reading
...
...
@@ -254,10 +255,10 @@ int p_symlink(const char *old, const char *new)
int
p_open
(
const
char
*
path
,
int
flags
,
...)
{
wchar_t
buf
[
GIT_WIN_PATH_UTF16
]
;
git_win_str_utf16
buf
;
mode_t
mode
=
0
;
git__utf8_to_16
(
buf
,
GIT_WIN_PATH_UTF16
,
path
);
git__utf8_to_16
(
buf
,
path
);
if
(
flags
&
O_CREAT
)
{
va_list
arg_list
;
...
...
@@ -272,8 +273,8 @@ int p_open(const char *path, int flags, ...)
int
p_creat
(
const
char
*
path
,
mode_t
mode
)
{
wchar_t
buf
[
GIT_WIN_PATH_UTF16
]
;
git__utf8_to_16
(
buf
,
GIT_WIN_PATH_UTF16
,
path
);
git_win_str_utf16
buf
;
git__utf8_to_16
(
buf
,
path
);
return
_wopen
(
buf
,
_O_WRONLY
|
_O_CREAT
|
_O_TRUNC
|
_O_BINARY
,
mode
);
}
...
...
@@ -315,23 +316,23 @@ int p_stat(const char* path, struct stat* buf)
int
p_chdir
(
const
char
*
path
)
{
wchar_t
buf
[
GIT_WIN_PATH_UTF16
]
;
git__utf8_to_16
(
buf
,
GIT_WIN_PATH_UTF16
,
path
);
git_win_str_utf16
buf
;
git__utf8_to_16
(
buf
,
path
);
return
_wchdir
(
buf
);
}
int
p_chmod
(
const
char
*
path
,
mode_t
mode
)
{
wchar_t
buf
[
GIT_WIN_PATH_UTF16
]
;
git__utf8_to_16
(
buf
,
GIT_WIN_PATH_UTF16
,
path
);
git_win_str_utf16
buf
;
git__utf8_to_16
(
buf
,
path
);
return
_wchmod
(
buf
,
mode
);
}
int
p_rmdir
(
const
char
*
path
)
{
int
error
;
wchar_t
buf
[
GIT_WIN_PATH_UTF16
]
;
git__utf8_to_16
(
buf
,
GIT_WIN_PATH_UTF16
,
path
);
git_win_str_utf16
buf
;
git__utf8_to_16
(
buf
,
path
);
error
=
_wrmdir
(
buf
);
...
...
@@ -347,18 +348,18 @@ int p_rmdir(const char* path)
int
p_hide_directory__w32
(
const
char
*
path
)
{
wchar_t
buf
[
GIT_WIN_PATH_UTF16
]
;
git__utf8_to_16
(
buf
,
GIT_WIN_PATH_UTF16
,
path
);
git_win_str_utf16
buf
;
git__utf8_to_16
(
buf
,
path
);
return
(
SetFileAttributesW
(
buf
,
FILE_ATTRIBUTE_HIDDEN
)
!=
0
)
?
0
:
-
1
;
}
char
*
p_realpath
(
const
char
*
orig_path
,
char
*
buffer
)
{
int
ret
;
wchar_t
orig_path_w
[
GIT_WIN_PATH_UTF16
]
;
wchar_t
buffer_w
[
GIT_WIN_PATH_UTF16
]
;
git_win_str_utf16
orig_path_w
;
git_win_str_utf16
buffer_w
;
git__utf8_to_16
(
orig_path_w
,
GIT_WIN_PATH_UTF16
,
orig_path
);
git__utf8_to_16
(
orig_path_w
,
orig_path
);
/* Implicitly use GetCurrentDirectory which can be a threading issue */
ret
=
GetFullPathNameW
(
orig_path_w
,
GIT_WIN_PATH_UTF16
,
buffer_w
,
NULL
);
...
...
@@ -448,18 +449,18 @@ int p_setenv(const char* name, const char* value, int overwrite)
int
p_access
(
const
char
*
path
,
mode_t
mode
)
{
wchar_t
buf
[
GIT_WIN_PATH_UTF16
]
;
git__utf8_to_16
(
buf
,
GIT_WIN_PATH_UTF16
,
path
);
git_win_str_utf16
buf
;
git__utf8_to_16
(
buf
,
path
);
return
_waccess
(
buf
,
mode
);
}
int
p_rename
(
const
char
*
from
,
const
char
*
to
)
{
wchar_t
wfrom
[
GIT_WIN_PATH_UTF16
]
;
wchar_t
wto
[
GIT_WIN_PATH_UTF16
]
;
git_win_str_utf16
wfrom
;
git_win_str_utf16
wto
;
git__utf8_to_16
(
wfrom
,
GIT_WIN_PATH_UTF16
,
from
);
git__utf8_to_16
(
wto
,
GIT_WIN_PATH_UTF16
,
to
);
git__utf8_to_16
(
wfrom
,
from
);
git__utf8_to_16
(
wto
,
to
);
return
MoveFileExW
(
wfrom
,
wto
,
MOVEFILE_REPLACE_EXISTING
|
MOVEFILE_COPY_ALLOWED
)
?
0
:
-
1
;
}
...
...
src/win32/utf-conv.c
View file @
9c38f7a6
...
...
@@ -70,12 +70,12 @@ void git__utf8_to_16(wchar_t *dest, size_t length, const char *src)
}
#endif
int
git__utf8_to_16
(
wchar_t
*
dest
,
size_t
length
,
const
char
*
src
)
int
git__utf8_to_16
(
git_win_str_utf16
dest
,
const
git_win_str_utf8
src
)
{
return
MultiByteToWideChar
(
CP_UTF8
,
0
,
src
,
-
1
,
dest
,
(
int
)
length
);
return
MultiByteToWideChar
(
CP_UTF8
,
0
,
src
,
-
1
,
dest
,
GIT_WIN_PATH_UTF16
);
}
int
git__utf16_to_8
(
char
*
out
,
const
wchar_t
*
input
)
int
git__utf16_to_8
(
git_win_str_utf8
dest
,
const
git_win_str_utf16
src
)
{
return
WideCharToMultiByte
(
CP_UTF8
,
0
,
input
,
-
1
,
ou
t
,
GIT_WIN_PATH_UTF8
,
NULL
,
NULL
);
return
WideCharToMultiByte
(
CP_UTF8
,
0
,
src
,
-
1
,
des
t
,
GIT_WIN_PATH_UTF8
,
NULL
,
NULL
);
}
src/win32/utf-conv.h
View file @
9c38f7a6
...
...
@@ -13,8 +13,11 @@
#define GIT_WIN_PATH_UTF16 (260 + 1)
#define GIT_WIN_PATH_UTF8 (260 * 4 + 1)
int
git__utf8_to_16
(
wchar_t
*
dest
,
size_t
length
,
const
char
*
src
);
int
git__utf16_to_8
(
char
*
dest
,
const
wchar_t
*
src
);
typedef
wchar_t
git_win_str_utf16
[
GIT_WIN_PATH_UTF16
];
typedef
char
git_win_str_utf8
[
GIT_WIN_PATH_UTF8
];
int
git__utf8_to_16
(
git_win_str_utf16
dest
,
const
git_win_str_utf8
src
);
int
git__utf16_to_8
(
git_win_str_utf8
dest
,
const
git_win_str_utf16
src
);
#endif
tests-clar/clar_libgit2.c
View file @
9c38f7a6
...
...
@@ -56,12 +56,12 @@ void cl_git_rewritefile(const char *filename, const char *new_content)
char
*
cl_getenv
(
const
char
*
name
)
{
wchar_t
name_utf16
[
GIT_WIN_PATH_UTF16
]
;
git_win_str_utf16
name_utf16
;
DWORD
alloc_len
;
wchar_t
*
value_utf16
;
char
*
value_utf8
;
git__utf8_to_16
(
name_utf16
,
GIT_WIN_PATH_UTF16
,
name
);
git__utf8_to_16
(
name_utf16
,
name
);
alloc_len
=
GetEnvironmentVariableW
(
name_utf16
,
NULL
,
0
);
if
(
alloc_len
<=
0
)
return
NULL
;
...
...
@@ -81,13 +81,13 @@ char *cl_getenv(const char *name)
int
cl_setenv
(
const
char
*
name
,
const
char
*
value
)
{
wchar_t
name_utf16
[
GIT_WIN_PATH_UTF16
]
;
wchar_t
value_utf16
[
GIT_WIN_PATH_UTF16
]
;
git_win_str_utf16
name_utf16
;
git_win_str_utf16
value_utf16
;
git__utf8_to_16
(
name_utf16
,
GIT_WIN_PATH_UTF16
,
name
);
git__utf8_to_16
(
name_utf16
,
name
);
if
(
value
)
{
git__utf8_to_16
(
value_utf16
,
GIT_WIN_PATH_UTF16
,
value
);
git__utf8_to_16
(
value_utf16
,
value
);
cl_assert
(
SetEnvironmentVariableW
(
name_utf16
,
value_utf16
));
}
else
{
/* Windows XP returns 0 (failed) when passing NULL for lpValue when
...
...
@@ -107,12 +107,12 @@ int cl_setenv(const char *name, const char *value)
* the source is a directory, a child of the source). */
int
cl_rename
(
const
char
*
source
,
const
char
*
dest
)
{
wchar_t
source_utf16
[
GIT_WIN_PATH_UTF16
]
;
wchar_t
dest_utf16
[
GIT_WIN_PATH_UTF16
]
;
git_win_str_utf16
source_utf16
;
git_win_str_utf16
dest_utf16
;
unsigned
retries
=
1
;
git__utf8_to_16
(
source_utf16
,
GIT_WIN_PATH_UTF16
,
source
);
git__utf8_to_16
(
dest_utf16
,
GIT_WIN_PATH_UTF16
,
dest
);
git__utf8_to_16
(
source_utf16
,
source
);
git__utf8_to_16
(
dest_utf16
,
dest
);
while
(
!
MoveFileW
(
source_utf16
,
dest_utf16
))
{
/* Only retry if the error is ERROR_ACCESS_DENIED;
...
...
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