]> granicus.if.org Git - php/commitdiff
preserve the error code
authorAnatol Belski <ab@php.net>
Fri, 18 Oct 2013 12:01:16 +0000 (05:01 -0700)
committerAnatol Belski <ab@php.net>
Fri, 18 Oct 2013 12:01:16 +0000 (05:01 -0700)
otherwise it'd be cleared by a subsequent calls

Zend/zend_virtual_cwd.c

index 968390d3539251991017a8156ae1a47f2803abdd..e171386b1b3d9444d8ca570e1e7b2884f4ff41fd 100644 (file)
@@ -1695,6 +1695,9 @@ CWD_API int virtual_rename(const char *oldname, const char *newname TSRMLS_DC) /
        cwd_state old_state;
        cwd_state new_state;
        int retval;
+#ifdef TSRM_WIN32
+       DWORD last_error;
+#endif
 
        CWD_STATE_COPY(&old_state, &CWDG(cwd));
        if (virtual_file_ex(&old_state, oldname, NULL, CWD_EXPAND TSRMLS_CC)) {
@@ -1716,6 +1719,7 @@ CWD_API int virtual_rename(const char *oldname, const char *newname TSRMLS_DC) /
 #ifdef TSRM_WIN32
        /* MoveFileEx returns 0 on failure, other way 'round for this function */
        retval = (MoveFileEx(oldname, newname, MOVEFILE_REPLACE_EXISTING|MOVEFILE_COPY_ALLOWED) == 0) ? -1 : 0;
+       last_error = GetLastError();
 #else
        retval = rename(oldname, newname);
 #endif
@@ -1723,6 +1727,10 @@ CWD_API int virtual_rename(const char *oldname, const char *newname TSRMLS_DC) /
        CWD_STATE_FREE(&old_state);
        CWD_STATE_FREE(&new_state);
 
+#ifdef TSRM_WIN32
+       SetLastError(last_error);
+#endif
+
        return retval;
 }
 /* }}} */