]> granicus.if.org Git - php/commitdiff
- [DOC] #45986, bad file descriptor warning when rename is used with invalid path...
authorPierre Joye <pajoye@php.net>
Tue, 26 Jan 2010 20:04:03 +0000 (20:04 +0000)
committerPierre Joye <pajoye@php.net>
Tue, 26 Jan 2010 20:04:03 +0000 (20:04 +0000)
main/main.c
main/php.h
main/streams/plain_wrapper.c

index 69d2b61217cd2b8f5b1c6dd293bf8bee4130599e..92e3ab4db864dbb6cbd491e9da10e36950ab5e94 100644 (file)
@@ -944,6 +944,27 @@ PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1,
 }
 /* }}} */
 
+#ifdef PHP_WIN32
+#define PHP_WIN32_ERROR_MSG_BUFFER_SIZE 512
+PHPAPI void php_win32_docref2_from_error(DWORD error, const char *param1, const char *param2 TSRMLS_DC) {
+       if (error == 0) {
+               php_error_docref2(NULL TSRMLS_CC, param1, param2, E_WARNING, "%s", strerror(errno));
+       } else {
+               char buf[PHP_WIN32_ERROR_MSG_BUFFER_SIZE + 1];
+               int buf_len;
+
+               FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, buf, PHP_WIN32_ERROR_MSG_BUFFER_SIZE, NULL);
+               buf_len = strlen(buf);
+               if (buf_len >= 2) {
+                       buf[buf_len - 1] = '\0';
+                       buf[buf_len - 2] = '\0';
+               }
+               php_error_docref2(NULL TSRMLS_CC, param1, param2, E_WARNING, "%s (code: %lu)", (char *)buf, error);
+       }
+}
+#undef PHP_WIN32_ERROR_MSG_BUFFER_SIZE
+#endif
+
 /* {{{ php_html_puts */
 PHPAPI void php_html_puts(const char *str, uint size TSRMLS_DC)
 {
index 7628b89a95da2dd206c6805f6128061254710e25..44d6c51d94015db128706879f24cd26454a03c9e 100644 (file)
@@ -306,6 +306,7 @@ PHPAPI void php_verror(const char *docref, const char *params, int type, const c
 PHPAPI void php_error_docref0(const char *docref TSRMLS_DC, int type, const char *format, ...);
 PHPAPI void php_error_docref1(const char *docref TSRMLS_DC, const char *param1, int type, const char *format, ...);
 PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...);
+PHPAPI void php_win32_docref2_from_error(DWORD error, const char *param1, const char *param2 TSRMLS_DC);
 END_EXTERN_C()
 
 #define php_error_docref php_error_docref0
index 4e165be649da43cd5b7c824cd4aeeff681b2df57..9ce31ac8dded845d74277b1b59766b2425a22ce2 100644 (file)
@@ -1057,12 +1057,13 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, char *url_from, c
        ret = VCWD_RENAME(url_from, url_to);
 
        if (ret == -1) {
-#ifdef EXDEV
+#ifndef PHP_WIN32
+# ifdef EXDEV
                if (errno == EXDEV) {
                        struct stat sb;
                        if (php_copy_file(url_from, url_to TSRMLS_CC) == SUCCESS) {
                                if (VCWD_STAT(url_from, &sb) == 0) {
-#if !defined(TSRM_WIN32) && !defined(NETWARE)
+#  if !defined(TSRM_WIN32) && !defined(NETWARE)
                                        if (VCWD_CHMOD(url_to, sb.st_mode)) {
                                                if (errno == EPERM) {
                                                        php_error_docref2(NULL TSRMLS_CC, url_from, url_to, E_WARNING, "%s", strerror(errno));
@@ -1081,7 +1082,7 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, char *url_from, c
                                                php_error_docref2(NULL TSRMLS_CC, url_from, url_to, E_WARNING, "%s", strerror(errno));
                                                return 0;
                                        }
-#endif
+#  endif
                                        VCWD_UNLINK(url_from);
                                        return 1;
                                }
@@ -1089,8 +1090,14 @@ static int php_plain_files_rename(php_stream_wrapper *wrapper, char *url_from, c
                        php_error_docref2(NULL TSRMLS_CC, url_from, url_to, E_WARNING, "%s", strerror(errno));
                        return 0;
                }
+# endif
 #endif
+
+#ifdef PHP_WIN32
+               php_win32_docref2_from_error(GetLastError(), url_from, url_to TSRMLS_CC);
+#else
                php_error_docref2(NULL TSRMLS_CC, url_from, url_to, E_WARNING, "%s", strerror(errno));
+#endif
         return 0;
        }