Skip to content

Commit

Permalink
- [DOC] #45986, bad file descriptor warning when rename is used with …
Browse files Browse the repository at this point in the history
…invalid path, add php_win32_docref2_from_error to display system error for non posix api
  • Loading branch information
pierrejoye committed Jan 26, 2010
1 parent daa380c commit 573c33b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
21 changes: 21 additions & 0 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,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)
{
Expand Down
2 changes: 2 additions & 0 deletions main/php.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ PHPAPI void php_error_docref1(const char *docref TSRMLS_DC, const char *param1,
PHP_ATTRIBUTE_FORMAT(printf, PHP_ATTR_FMT_OFFSET + 4, PHP_ATTR_FMT_OFFSET + 5);
PHPAPI void php_error_docref2(const char *docref TSRMLS_DC, const char *param1, const char *param2, int type, const char *format, ...)
PHP_ATTRIBUTE_FORMAT(printf, PHP_ATTR_FMT_OFFSET + 5, PHP_ATTR_FMT_OFFSET + 6);
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
Expand Down
13 changes: 10 additions & 3 deletions main/streams/plain_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,12 +1080,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));
Expand All @@ -1104,16 +1105,22 @@ 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;
}
}
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;
}

Expand Down

0 comments on commit 573c33b

Please sign in to comment.