diff options
Diffstat (limited to 'src/win32')
-rw-r--r-- | src/win32/posix.h | 2 | ||||
-rw-r--r-- | src/win32/posix_w32.c | 32 | ||||
-rw-r--r-- | src/win32/utf-conv.c | 31 |
3 files changed, 40 insertions, 25 deletions
diff --git a/src/win32/posix.h b/src/win32/posix.h index 60adc9666..d13d3e39b 100644 --- a/src/win32/posix.h +++ b/src/win32/posix.h @@ -49,5 +49,7 @@ extern int p_open(const char *path, int flags); extern int p_creat(const char *path, mode_t mode); extern int p_getcwd(char *buffer_out, size_t size); extern int p_rename(const char *from, const char *to); +extern int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags); +extern int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags); #endif diff --git a/src/win32/posix_w32.c b/src/win32/posix_w32.c index c6b36a847..8af664165 100644 --- a/src/win32/posix_w32.c +++ b/src/win32/posix_w32.c @@ -4,7 +4,7 @@ * This file is part of libgit2, distributed under the GNU GPL v2 with * a Linking Exception. For full terms see the included COPYING file. */ -#include "posix.h" +#include "../posix.h" #include "path.h" #include "utf-conv.h" #include <errno.h> @@ -179,11 +179,11 @@ int p_readlink(const char *link, char *target, size_t target_len) target_w = (wchar_t*)git__malloc(target_len * sizeof(wchar_t)); GITERR_CHECK_ALLOC(target_w); - dwRet = pGetFinalPath(hFile, target_w, target_len, 0x0); + dwRet = pGetFinalPath(hFile, target_w, (DWORD)target_len, 0x0); if (dwRet == 0 || dwRet >= target_len || !WideCharToMultiByte(CP_UTF8, 0, target_w, -1, target, - target_len * sizeof(char), NULL, NULL)) + (int)(target_len * sizeof(char)), NULL, NULL)) error = -1; git__free(target_w); @@ -241,13 +241,19 @@ int p_creat(const char *path, mode_t mode) int p_getcwd(char *buffer_out, size_t size) { - wchar_t* buf = (wchar_t*)git__malloc(sizeof(wchar_t) * (int)size); int ret; + wchar_t* buf; + + if ((size_t)((int)size) != size) + return -1; + + buf = (wchar_t*)git__malloc(sizeof(wchar_t) * (int)size); + GITERR_CHECK_ALLOC(buf); _wgetcwd(buf, (int)size); ret = WideCharToMultiByte( - CP_UTF8, 0, buf, -1, buffer_out, size, NULL, NULL); + CP_UTF8, 0, buf, -1, buffer_out, (int)size, NULL, NULL); git__free(buf); return !ret ? -1 : 0; @@ -421,3 +427,19 @@ int p_rename(const char *from, const char *to) return ret; } + +int p_recv(GIT_SOCKET socket, void *buffer, size_t length, int flags) +{ + if ((size_t)((int)length) != length) + return -1; /* giterr_set will be done by caller */ + + return recv(socket, buffer, (int)length, flags); +} + +int p_send(GIT_SOCKET socket, const void *buffer, size_t length, int flags) +{ + if ((size_t)((int)length) != length) + return -1; /* giterr_set will be done by caller */ + + return send(socket, buffer, (int)length, flags); +} diff --git a/src/win32/utf-conv.c b/src/win32/utf-conv.c index f00f5be92..fbcb69d0a 100644 --- a/src/win32/utf-conv.c +++ b/src/win32/utf-conv.c @@ -31,27 +31,23 @@ void gitwin_set_utf8(void) wchar_t* gitwin_to_utf16(const char* str) { wchar_t* ret; - int cb; + size_t cb; if (!str) return NULL; cb = strlen(str) * sizeof(wchar_t); - if (cb == 0) { - ret = (wchar_t*)git__malloc(sizeof(wchar_t)); - if (ret) - ret[0] = 0; - return ret; - } + if (cb == 0) + return (wchar_t *)git__calloc(1, sizeof(wchar_t)); /* Add space for null terminator */ cb += sizeof(wchar_t); - ret = (wchar_t*)git__malloc(cb); + ret = (wchar_t *)git__malloc(cb); if (!ret) return NULL; - if (MultiByteToWideChar(_active_codepage, 0, str, -1, ret, cb) == 0) { + if (MultiByteToWideChar(_active_codepage, 0, str, -1, ret, (int)cb) == 0) { giterr_set(GITERR_OS, "Could not convert string to UTF-16"); git__free(ret); ret = NULL; @@ -62,7 +58,7 @@ wchar_t* gitwin_to_utf16(const char* str) int gitwin_append_utf16(wchar_t *buffer, const char *str, size_t len) { - int result = MultiByteToWideChar(_active_codepage, 0, str, -1, buffer, len); + int result = MultiByteToWideChar(_active_codepage, 0, str, -1, buffer, (int)len); if (result == 0) giterr_set(GITERR_OS, "Could not convert string to UTF-16"); return result; @@ -71,19 +67,14 @@ int gitwin_append_utf16(wchar_t *buffer, const char *str, size_t len) char* gitwin_from_utf16(const wchar_t* str) { char* ret; - int cb; + size_t cb; - if (!str) { + if (!str) return NULL; - } cb = wcslen(str) * sizeof(char); - if (cb == 0) { - ret = (char*)git__malloc(sizeof(char)); - if (ret) - ret[0] = 0; - return ret; - } + if (cb == 0) + return (char *)git__calloc(1, sizeof(char)); /* Add space for null terminator */ cb += sizeof(char); @@ -92,7 +83,7 @@ char* gitwin_from_utf16(const wchar_t* str) if (!ret) return NULL; - if (WideCharToMultiByte(_active_codepage, 0, str, -1, ret, cb, NULL, NULL) == 0) { + if (WideCharToMultiByte(_active_codepage, 0, str, -1, ret, (int)cb, NULL, NULL) == 0) { giterr_set(GITERR_OS, "Could not convert string to UTF-8"); git__free(ret); ret = NULL; |