Skip to content

Commit 4bdd635

Browse files
committed
Merge branch 'PHP-7.1'
* PHP-7.1: improve error handling
2 parents 1507f30 + 02e9e59 commit 4bdd635

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

win32/ioutil.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ __forceinline static int php_win32_ioutil_access(const char *path, mode_t mode)
246246
PHP_WIN32_IOUTIL_CHECK_PATH_W(pathw, -1, 1)
247247

248248
ret = _waccess(pathw, mode);
249-
_get_errno(&err);
249+
if (0 > ret) {
250+
_get_errno(&err);
251+
}
250252
PHP_WIN32_IOUTIL_CLEANUP_W()
251253

252254
if (0 > ret) {
@@ -279,7 +281,9 @@ __forceinline static int php_win32_ioutil_open(const char *path, int flags, ...)
279281
}
280282

281283
ret = php_win32_ioutil_open_w(pathw, flags, mode);
282-
err = GetLastError();
284+
if (0 > ret) {
285+
err = GetLastError();
286+
}
283287
PHP_WIN32_IOUTIL_CLEANUP_W()
284288

285289
if (0 > ret) {
@@ -368,7 +372,9 @@ __forceinline static FILE *php_win32_ioutil_fopen(const char *patha, const char
368372
}
369373

370374
ret = _wfopen(pathw, modew);
371-
_get_errno(&err);
375+
if (!ret) {
376+
_get_errno(&err);
377+
}
372378
free(pathw);
373379
free(modew);
374380

@@ -405,7 +411,9 @@ __forceinline static int php_win32_ioutil_rename(const char *oldnamea, const cha
405411
}
406412

407413
ret = php_win32_ioutil_rename_w(oldnamew, newnamew);
408-
err = GetLastError();
414+
if (0 > ret) {
415+
err = GetLastError();
416+
}
409417

410418
free(oldnamew);
411419
free(newnamew);
@@ -429,7 +437,9 @@ __forceinline static int php_win32_ioutil_chdir(const char *patha)
429437
}
430438

431439
ret = php_win32_ioutil_chdir_w(pathw);
432-
err = GetLastError();
440+
if (0 > ret) {
441+
err = GetLastError();
442+
}
433443

434444
free(pathw);
435445

@@ -495,7 +505,9 @@ __forceinline static int php_win32_ioutil_chmod(const char *patha, int mode)
495505
PHP_WIN32_IOUTIL_CHECK_PATH_W(pathw, -1, 1)
496506

497507
ret = _wchmod(pathw, mode);
498-
_get_errno(&err);
508+
if (0 > ret) {
509+
_get_errno(&err);
510+
}
499511

500512
free(pathw);
501513

0 commit comments

Comments
 (0)