Skip to content

Commit 02e9e59

Browse files
committed
improve error handling
1 parent 6e3d24b commit 02e9e59

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
@@ -244,7 +244,9 @@ __forceinline static int php_win32_ioutil_access(const char *path, mode_t mode)
244244
PHP_WIN32_IOUTIL_CHECK_PATH_W(pathw, -1, 1)
245245

246246
ret = _waccess(pathw, mode);
247-
_get_errno(&err);
247+
if (0 > ret) {
248+
_get_errno(&err);
249+
}
248250
PHP_WIN32_IOUTIL_CLEANUP_W()
249251

250252
if (0 > ret) {
@@ -277,7 +279,9 @@ __forceinline static int php_win32_ioutil_open(const char *path, int flags, ...)
277279
}
278280

279281
ret = php_win32_ioutil_open_w(pathw, flags, mode);
280-
err = GetLastError();
282+
if (0 > ret) {
283+
err = GetLastError();
284+
}
281285
PHP_WIN32_IOUTIL_CLEANUP_W()
282286

283287
if (0 > ret) {
@@ -366,7 +370,9 @@ __forceinline static FILE *php_win32_ioutil_fopen(const char *patha, const char
366370
}
367371

368372
ret = _wfopen(pathw, modew);
369-
_get_errno(&err);
373+
if (!ret) {
374+
_get_errno(&err);
375+
}
370376
free(pathw);
371377
free(modew);
372378

@@ -403,7 +409,9 @@ __forceinline static int php_win32_ioutil_rename(const char *oldnamea, const cha
403409
}
404410

405411
ret = php_win32_ioutil_rename_w(oldnamew, newnamew);
406-
err = GetLastError();
412+
if (0 > ret) {
413+
err = GetLastError();
414+
}
407415

408416
free(oldnamew);
409417
free(newnamew);
@@ -427,7 +435,9 @@ __forceinline static int php_win32_ioutil_chdir(const char *patha)
427435
}
428436

429437
ret = php_win32_ioutil_chdir_w(pathw);
430-
err = GetLastError();
438+
if (0 > ret) {
439+
err = GetLastError();
440+
}
431441

432442
free(pathw);
433443

@@ -493,7 +503,9 @@ __forceinline static int php_win32_ioutil_chmod(const char *patha, int mode)
493503
PHP_WIN32_IOUTIL_CHECK_PATH_W(pathw, -1, 1)
494504

495505
ret = _wchmod(pathw, mode);
496-
_get_errno(&err);
506+
if (0 > ret) {
507+
_get_errno(&err);
508+
}
497509

498510
free(pathw);
499511

0 commit comments

Comments
 (0)