Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0a6cd06

Browse files
committed
Zend: Refactor virtual_rmdir() to take path lengths
1 parent f0b3e7b commit 0a6cd06

File tree

6 files changed

+39
-50
lines changed

6 files changed

+39
-50
lines changed

‎UPGRADING.INTERNALS

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,15 @@ PHP 8.4 INTERNALS UPGRADE NOTES
107107
* Removed ZEND_DIM_ALTERNATIVE_SYNTAX constant. This syntax no longer has a
108108
specialized error message.
109109

110-
* The virtual_file_ex() function now has an extra parameter for the path
111-
length.
112-
113-
* The virtual_chdir_file() function and corresponding VCWD_CHDIR_FILE() macro
114-
now have an extra parameter for the path length.
115-
116-
* The virtual_rename() function and corresponding VCWD_RENAME() macro
117-
now have extra parameters for the path lengths.
110+
* The following functions and macros now takes extra arguments for the lengths
111+
of paths:
112+
- virtual_file_ex()
113+
- virtual_chdir_file()
114+
- VCWD_CHDIR_FILE()
115+
- virtual_rename()
116+
- VCWD_RENAME()
117+
- virtual_rmdir()
118+
- VCWD_RMDIR()
118119

119120
========================
120121
2. Build system changes
@@ -394,5 +395,6 @@ PHP 8.4 INTERNALS UPGRADE NOTES
394395
6. Windows changes
395396
========================
396397

397-
* The php_win32_ioutil_rename() function now takes extra arguments for the
398-
lengths of the names.
398+
* The following functions now takes extra arguments for the lengths of paths:
399+
- php_win32_ioutil_rmdir()
400+
- php_win32_ioutil_rename()

‎Zend/zend_virtual_cwd.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,22 +1620,21 @@ CWD_API int virtual_mkdir(const char *pathname, mode_t mode) /* {{{ */
16201620
}
16211621
/* }}} */
16221622

1623-
CWD_API int virtual_rmdir(const char *pathname) /* {{{ */
1623+
CWD_API zend_result virtual_rmdir(const char *path, size_tpath_length) /* {{{ */
16241624
{
16251625
cwd_state new_state;
1626-
int retval;
1627-
size_t path_length = strlen(pathname);
16281626

16291627
CWD_STATE_COPY(&new_state, &CWDG(cwd));
1630-
if (virtual_file_ex(&new_state, pathname, path_length, NULL, CWD_EXPAND)) {
1628+
if (virtual_file_ex(&new_state, path, path_length, NULL, CWD_EXPAND)) {
16311629
CWD_STATE_FREE_ERR(&new_state);
1632-
return -1;
1630+
return FAILURE;
16331631
}
16341632

1633+
zend_result retval;
16351634
#ifdef ZEND_WIN32
1636-
retval = php_win32_ioutil_rmdir(new_state.cwd);
1635+
retval = php_win32_ioutil_rmdir(new_state.cwd, new_state.cwd_length);
16371636
#else
1638-
retval = rmdir(new_state.cwd);
1637+
retval = virtual_rmdir_native(new_state.cwd, new_state.cwd_length);
16391638
#endif
16401639
CWD_STATE_FREE_ERR(&new_state);
16411640
return retval;

‎Zend/zend_virtual_cwd.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ CWD_API int virtual_stat(const char *path, zend_stat_t *buf);
185185
CWD_API int virtual_lstat(const char *path, zend_stat_t *buf);
186186
CWD_API int virtual_unlink(const char *path);
187187
CWD_API int virtual_mkdir(const char *pathname, mode_t mode);
188-
CWD_API int virtual_rmdir(const char *pathname);
188+
CWD_API zend_result virtual_rmdir(const char *path, size_tpath_len);
189189
CWD_API DIR *virtual_opendir(const char *pathname);
190190
CWD_API FILE *virtual_popen(const char *command, const char *type);
191191
CWD_API int virtual_access(const char *pathname, int mode);
@@ -260,6 +260,10 @@ static zend_always_inline zend_result virtual_rename_native(const char *old_name
260260
return (rename(old_name, new_name) == 0) ? SUCCESS : FAILURE;
261261
}
262262

263+
static zend_always_inline zend_result virtual_rmdir_native(const char *path, ZEND_ATTRIBUTE_UNUSED size_t path_len) {
264+
return (rmdir(path) == 0) ? SUCCESS : FAILURE;
265+
}
266+
263267
#ifdef CWD_EXPORTS
264268
extern void virtual_cwd_main_cwd_init(uint8_t);
265269
#endif
@@ -285,8 +289,8 @@ extern void virtual_cwd_main_cwd_init(uint8_t);
285289
#define VCWD_STAT(path, buff) virtual_stat(path, buff)
286290
# define VCWD_LSTAT(path, buff) virtual_lstat(path, buff)
287291
#define VCWD_UNLINK(path) virtual_unlink(path)
288-
#define VCWD_MKDIR(pathname, mode) virtual_mkdir(pathname, mode)
289-
#define VCWD_RMDIR(pathname) virtual_rmdir(pathname)
292+
#define VCWD_MKDIR(path, mode) virtual_mkdir(path, mode)
293+
#define VCWD_RMDIR(path, path_len) virtual_rmdir(path, path_len)
290294
#define VCWD_OPENDIR(pathname) virtual_opendir(pathname)
291295
#define VCWD_POPEN(command, type) virtual_popen(command, type)
292296
#define VCWD_ACCESS(pathname, mode) virtual_access(pathname, mode)
@@ -311,8 +315,8 @@ extern void virtual_cwd_main_cwd_init(uint8_t);
311315
#define VCWD_OPEN(path, flags) php_win32_ioutil_open(path, flags)
312316
#define VCWD_OPEN_MODE(path, flags, mode) php_win32_ioutil_open(path, flags, mode)
313317
#define VCWD_RENAME(old_name, old_name_length, new_name, new_name_length) php_win32_ioutil_rename(old_name, old_name_length, new_name, new_name_length)
314-
#define VCWD_MKDIR(pathname, mode) php_win32_ioutil_mkdir(pathname, mode)
315-
#define VCWD_RMDIR(pathname) php_win32_ioutil_rmdir(pathname)
318+
#define VCWD_MKDIR(path, mode) php_win32_ioutil_mkdir(path, mode)
319+
#define VCWD_RMDIR(path, path_length) php_win32_ioutil_rmdir(path, path_length)
316320
#define VCWD_UNLINK(path) php_win32_ioutil_unlink(path)
317321
#define VCWD_CHDIR(path) php_win32_ioutil_chdir(path)
318322
#define VCWD_ACCESS(pathname, mode) tsrm_win32_access(pathname, mode)
@@ -324,7 +328,7 @@ extern void virtual_cwd_main_cwd_init(uint8_t);
324328
#define VCWD_OPEN_MODE(path, flags, mode) open(path, flags, mode)
325329
#define VCWD_RENAME(old_name, old_name_len, new_name, new_name_len) virtual_rename_native(old_name, old_name_len, new_name, new_name_len)
326330
#define VCWD_MKDIR(path, mode) mkdir(path, mode)
327-
#define VCWD_RMDIR(pathname) rmdir(pathname)
331+
#define VCWD_RMDIR(path, path_len) virtual_rmdir_native(path, path_len)
328332
#define VCWD_UNLINK(path) unlink(path)
329333
#define VCWD_CHDIR(path) chdir(path)
330334
#define VCWD_ACCESS(pathname, mode) access(pathname, mode)

‎main/streams/plain_wrapper.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,14 +1471,15 @@ static int php_plain_files_rmdir(php_stream_wrapper *wrapper, const char *url, i
14711471
return 0;
14721472
}
14731473

1474+
size_t url_len = strlen(url);
14741475
#ifdef PHP_WIN32
1475-
if (!php_win32_check_trailing_space(url, strlen(url))) {
1476+
if (!php_win32_check_trailing_space(url, url_len)) {
14761477
php_error_docref1(NULL, url, E_WARNING, "%s", strerror(ENOENT));
14771478
return 0;
14781479
}
14791480
#endif
14801481

1481-
if (VCWD_RMDIR(url) < 0) {
1482+
if (VCWD_RMDIR(url, url_len) < 0) {
14821483
php_error_docref1(NULL, url, E_WARNING, "%s", strerror(errno));
14831484
return 0;
14841485
}

‎win32/ioutil.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -436,21 +436,6 @@ PW32IO int php_win32_ioutil_unlink_w(const wchar_t *path)
436436
return 0;
437437
}/*}}}*/
438438

439-
PW32IO int php_win32_ioutil_rmdir_w(const wchar_t *path)
440-
{/*{{{*/
441-
int ret = 0;
442-
443-
PHP_WIN32_IOUTIL_CHECK_PATH_W(path, -1, 0)
444-
445-
if (!RemoveDirectoryW(path)) {
446-
DWORD err = GetLastError();
447-
ret = -1;
448-
SET_ERRNO_FROM_WIN32_CODE(err);
449-
}
450-
451-
return ret;
452-
}/*}}}*/
453-
454439
PW32IO int php_win32_ioutil_chdir_w(const wchar_t *path)
455440
{/*{{{*/
456441
int ret = 0;

‎win32/ioutil.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -359,30 +359,28 @@ __forceinline static int php_win32_ioutil_unlink(const char *path)
359359
return ret;
360360
}/*}}}*/
361361

362-
__forceinline static int php_win32_ioutil_rmdir(const char *path)
362+
__forceinline static zend_result php_win32_ioutil_rmdir(const char *path, size_tpath_len)
363363
{/*{{{*/
364+
// TODO Is it possible to use php_win32_ioutil_conv_any_to_w() with path_len?
364365
PHP_WIN32_IOUTIL_INIT_W(path)
365-
int ret = 0;
366366
DWORD err = 0;
367367

368368
if (!pathw) {
369369
SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_PARAMETER);
370-
return -1;
370+
return FAILURE;
371371
}
372372

373-
PHP_WIN32_IOUTIL_CHECK_PATH_W(pathw, -1, 1)
373+
PHP_WIN32_IOUTIL_CHECK_PATH_W(pathw, FAILURE, 1)
374374

375+
zend_result ret = SUCCESS;
375376
if (!RemoveDirectoryW(pathw)) {
376-
err = GetLastError();
377-
ret = -1;
377+
DWORD err = GetLastError();
378+
SET_ERRNO_FROM_WIN32_CODE(err);
379+
ret = FAILURE;
378380
}
379381

380382
PHP_WIN32_IOUTIL_CLEANUP_W()
381383

382-
if (0 > ret) {
383-
SET_ERRNO_FROM_WIN32_CODE(err);
384-
}
385-
386384
return ret;
387385
}/*}}}*/
388386

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /