com php-src: improve error handling: win32/ioutil.h

[email protected] (Anatol Belski)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    02e9e59bebd793905a6d833413449515e9e42160
Author:    Anatol Belski <[email protected]>         Wed, 17 May 2017 13:35:42 +0200
Parents:   6e3d24bcf42413cc96875e8775e4cac769eb64aa
Branches:  PHP-7.1 master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=02e9e59bebd793905a6d833413449515e9e42160

Log:
improve error handling

Changed paths:
  M  win32/ioutil.h


Diff:
diff --git a/win32/ioutil.h b/win32/ioutil.h
index 1e781c6..f0c1f53 100644
--- a/win32/ioutil.h
+++ b/win32/ioutil.h
@@ -244,7 +244,9 @@ __forceinline static int php_win32_ioutil_access(const char *path, mode_t mode)
 	PHP_WIN32_IOUTIL_CHECK_PATH_W(pathw, -1, 1)
 
 	ret = _waccess(pathw, mode);
-	_get_errno(&err);
+	if (0 > ret) {
+		_get_errno(&err);
+	}
 	PHP_WIN32_IOUTIL_CLEANUP_W()
 
 	if (0 > ret) {
@@ -277,7 +279,9 @@ __forceinline static int php_win32_ioutil_open(const char *path, int flags, ...)
 	}
 
 	ret = php_win32_ioutil_open_w(pathw, flags, mode);
-	err = GetLastError();
+	if (0 > ret) {
+		err = GetLastError();
+	}
 	PHP_WIN32_IOUTIL_CLEANUP_W()
 
 	if (0 > ret) {
@@ -366,7 +370,9 @@ __forceinline static FILE *php_win32_ioutil_fopen(const char *patha, const char
 	}
 
 	ret = _wfopen(pathw, modew);
-	_get_errno(&err);
+	if (!ret) {
+		_get_errno(&err);
+	}
 	free(pathw);
 	free(modew);
 
@@ -403,7 +409,9 @@ __forceinline static int php_win32_ioutil_rename(const char *oldnamea, const cha
 	}
 
 	ret = php_win32_ioutil_rename_w(oldnamew, newnamew);
-	err = GetLastError();
+	if (0 > ret) {
+		err = GetLastError();
+	}
 
 	free(oldnamew);
 	free(newnamew);
@@ -427,7 +435,9 @@ __forceinline static int php_win32_ioutil_chdir(const char *patha)
 	}
 
 	ret = php_win32_ioutil_chdir_w(pathw);
-	err = GetLastError();
+	if (0 > ret) {
+		err = GetLastError();
+	}
 
 	free(pathw);
 
@@ -493,7 +503,9 @@ __forceinline static int php_win32_ioutil_chmod(const char *patha, int mode)
 	PHP_WIN32_IOUTIL_CHECK_PATH_W(pathw, -1, 1)
 
 	ret = _wchmod(pathw, mode);
-	_get_errno(&err);
+	if (0 > ret) {
+		_get_errno(&err);
+	}
 
 	free(pathw);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.