com php-src: add more errno handling: win32/codepage.c win32/winutil.c

From: Date: Fri, 29 Jul 2016 13:05:41 +0000
Subject: com php-src: add more errno handling: win32/codepage.c win32/winutil.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-93473@lists.php.net to get a copy of this message
Commit: d6f7020eaac62f0beecd69e29e0ce1ded9bfc48d Author: Anatol Belski <ab@php.net> Fri, 29 Jul 2016 15:05:41 +0200 Parents: d8403aa019edbaef276124da4afa4f71127c568d Branches: PHP-7.1 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d6f7020eaac62f0beecd69e29e0ce1ded9bfc48d Log: add more errno handling Changed paths: M win32/codepage.c M win32/winutil.c Diff: diff --git a/win32/codepage.c b/win32/codepage.c index 409c527..3769b96 100644 --- a/win32/codepage.c +++ b/win32/codepage.c @@ -32,6 +32,7 @@ __forceinline static wchar_t *php_win32_cp_to_w_int(const char* in, size_t in_le int ret_len, tmp_len; if (!in || in_len > (size_t)INT_MAX) { + SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETERER); return NULL; } assert(in_len ? in[in_len] == L'\0' : 1); @@ -40,17 +41,20 @@ __forceinline static wchar_t *php_win32_cp_to_w_int(const char* in, size_t in_le ret_len = MultiByteToWideChar(cp, flags, in, tmp_len, NULL, 0); if (ret_len == 0) { + SET_ERRNO_FROM_WIN32_CODE(GetLastError()); return NULL; } ret = malloc(ret_len * sizeof(wchar_t)); if (!ret) { + SET_ERRNO_FROM_WIN32_CODE(ERROR_OUTOFMEMORY); return NULL; } tmp_len = MultiByteToWideChar(cp, flags, in, tmp_len, ret, ret_len); if (tmp_len == 0) { free(ret); + SET_ERRNO_FROM_WIN32_CODE(GetLastError()); return NULL; } @@ -93,11 +97,13 @@ PW32CP wchar_t *php_win32_cp_conv_ascii_to_w(const char* in, size_t in_len, size assert(in && in_len ? in[in_len] == '\0' : 1); if (!in) { + SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETERER); return NULL; } else if (0 == in_len) { /* Not binary safe. */ in_len = strlen(in); if (in_len > (size_t)INT_MAX) { + SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETERER); return NULL; } } @@ -118,6 +124,7 @@ PW32CP wchar_t *php_win32_cp_conv_ascii_to_w(const char* in, size_t in_len, size ret = malloc((in_len+1)*sizeof(wchar_t)); if (!ret) { + SET_ERRNO_FROM_WIN32_CODE(ERROR_OUTOFMEMORY); return NULL; } @@ -127,6 +134,7 @@ PW32CP wchar_t *php_win32_cp_conv_ascii_to_w(const char* in, size_t in_len, size if (-1 == k) { free(ret); + SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETERER); return NULL; } @@ -163,6 +171,7 @@ __forceinline static char *php_win32_cp_from_w_int(const wchar_t* in, size_t in_ char* target; if (!in || in_len > INT_MAX) { + SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETERER); return NULL; } assert(in_len ? in[in_len] == '\0' : 1); @@ -171,19 +180,20 @@ __forceinline static char *php_win32_cp_from_w_int(const wchar_t* in, size_t in_ target_len = WideCharToMultiByte(cp, flags, in, tmp_len, NULL, 0, NULL, NULL); if (target_len == 0) { + SET_ERRNO_FROM_WIN32_CODE(GetLastError()); return NULL; } target = malloc(target_len); if (target == NULL) { - SetLastError(ERROR_OUTOFMEMORY); - _set_errno(ENOMEM); + SET_ERRNO_FROM_WIN32_CODE(ERROR_OUTOFMEMORY); return NULL; } r = WideCharToMultiByte(cp, flags, in, tmp_len, target, target_len, NULL, NULL); if (r == 0) { free(target); + SET_ERRNO_FROM_WIN32_CODE(GetLastError()); return NULL; } @@ -258,6 +268,8 @@ PW32CP const struct php_win32_cp *php_win32_cp_get_by_id(DWORD id) } } + SET_ERRNO_FROM_WIN32_CODE(ERROR_NOT_FOUND); + return NULL; }/*}}}*/ @@ -311,6 +323,7 @@ PW32CP const struct php_win32_cp *php_win32_cp_set_by_id(DWORD id) {/*{{{*/ const struct php_win32_cp *tmp; if (!IsValidCodePage(id)) { + SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER); return NULL; } @@ -334,6 +347,7 @@ PW32CP wchar_t *php_win32_cp_env_any_to_w(const char* env) size_t bin_len = 0; if (!env) { + SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER); return NULL; } diff --git a/win32/winutil.c b/win32/winutil.c index 9afbb66..cd009ca 100644 --- a/win32/winutil.c +++ b/win32/winutil.c @@ -397,6 +397,8 @@ PHP_WINUTIL_API int php_win32_code_to_errno(unsigned long w32Err) /* 996 */ , { ERROR_IO_INCOMPLETE , EAGAIN } /* 997 */ , { ERROR_IO_PENDING , EAGAIN } + /* 1004 */ , { ERROR_INVALID_FLAGS , EINVAL } + /* 1113 */ , { ERROR_NO_UNICODE_TRANSLATION , EINVAL } /* 1168 */ , { ERROR_NOT_FOUND , ENOENT } /* 1816 */ , { ERROR_NOT_ENOUGH_QUOTA , ENOMEM } , { ERROR_ABANDONED_WAIT_0 , EIO }

« previous php.cvs (#93473) next »