vendor/libgit2/src/win32/utf-conv.c in rugged-0.21.4 vs vendor/libgit2/src/win32/utf-conv.c in rugged-0.22.0b1

- old
+ new

@@ -24,37 +24,24 @@ } return flags; } -GIT_INLINE(void) git__set_errno(void) -{ - if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) - errno = ENAMETOOLONG; - else - errno = EINVAL; -} - /** * Converts a UTF-8 string to wide characters. * * @param dest The buffer to receive the wide string. * @param dest_size The size of the buffer, in characters. * @param src The UTF-8 string to convert. * @return The length of the wide string, in characters (not counting the NULL terminator), or < 0 for failure */ int git__utf8_to_16(wchar_t *dest, size_t dest_size, const char *src) { - int len; - /* Length of -1 indicates NULL termination of the input string. Subtract 1 from the result to * turn 0 into -1 (an error code) and to not count the NULL terminator as part of the string's * length. MultiByteToWideChar never returns int's minvalue, so underflow is not possible */ - if ((len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, src, -1, dest, (int)dest_size) - 1) < 0) - git__set_errno(); - - return len; + return MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, src, -1, dest, (int)dest_size) - 1; } /** * Converts a wide string to UTF-8. * @@ -63,19 +50,14 @@ * @param src The wide string to convert. * @return The length of the UTF-8 string, in bytes (not counting the NULL terminator), or < 0 for failure */ int git__utf16_to_8(char *dest, size_t dest_size, const wchar_t *src) { - int len; - /* Length of -1 indicates NULL termination of the input string. Subtract 1 from the result to * turn 0 into -1 (an error code) and to not count the NULL terminator as part of the string's * length. WideCharToMultiByte never returns int's minvalue, so underflow is not possible */ - if ((len = WideCharToMultiByte(CP_UTF8, get_wc_flags(), src, -1, dest, (int)dest_size, NULL, NULL) - 1) < 0) - git__set_errno(); - - return len; + return WideCharToMultiByte(CP_UTF8, get_wc_flags(), src, -1, dest, (int)dest_size, NULL, NULL) - 1; } /** * Converts a UTF-8 string to wide characters. * Memory is allocated to hold the converted string. @@ -92,27 +74,21 @@ *dest = NULL; /* Length of -1 indicates NULL termination of the input string */ utf16_size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, src, -1, NULL, 0); - if (!utf16_size) { - git__set_errno(); + if (!utf16_size) return -1; - } *dest = git__malloc(utf16_size * sizeof(wchar_t)); - if (!*dest) { - errno = ENOMEM; + if (!*dest) return -1; - } utf16_size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, src, -1, *dest, utf16_size); if (!utf16_size) { - git__set_errno(); - git__free(*dest); *dest = NULL; } /* Subtract 1 from the result to turn 0 into -1 (an error code) and to not count the NULL @@ -138,26 +114,20 @@ *dest = NULL; /* Length of -1 indicates NULL termination of the input string */ utf8_size = WideCharToMultiByte(CP_UTF8, dwFlags, src, -1, NULL, 0, NULL, NULL); - if (!utf8_size) { - git__set_errno(); + if (!utf8_size) return -1; - } *dest = git__malloc(utf8_size); - if (!*dest) { - errno = ENOMEM; + if (!*dest) return -1; - } utf8_size = WideCharToMultiByte(CP_UTF8, dwFlags, src, -1, *dest, utf8_size, NULL, NULL); if (!utf8_size) { - git__set_errno(); - git__free(*dest); *dest = NULL; } /* Subtract 1 from the result to turn 0 into -1 (an error code) and to not count the NULL