com php-src: The d_name member of struct dirent sho uld be a pointer: win32/readdir.c win32/r eaddir.h
[email protected] (Anatol Belski)
| Newsgroups | php.cvs |
|---|---|
| Message-ID | <[email protected]> |
Commit: 0d529d6eb323d425615050dae97584e5fad14b30 Author: Anatol Belski <[email protected]> Sun, 12 Feb 2017 22:13:21 +0100 Parents: e637cd82a01747dd47733e873c9423e9903ea170 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=0d529d6eb323d425615050dae97584e5fad14b30 Log: The d_name member of struct dirent should be a pointer Rework for 60950702, so then any encoding is supported. The path segment length is measured in wchar_t size, whereby the number of wchar_t is 255+\0. This means, in the actual encoding, the path segment size can become (255*<bytes per glyph>)+\0 bytes in worst case. It is still valid, as all the FS API uses wide chars internally. Changed paths: M win32/readdir.c M win32/readdir.h Diff: diff --git a/win32/readdir.c b/win32/readdir.c index 42b528a..1031fe2 100644 --- a/win32/readdir.c +++ b/win32/readdir.c @@ -37,7 +37,7 @@ DIR *opendir(const char *dir) return NULL; } - dp = (DIR *) malloc(sizeof(DIR)); + dp = (DIR *) calloc(1, sizeof(DIR)); if (dp == NULL) { return NULL; } @@ -87,6 +87,7 @@ DIR *opendir(const char *dir) struct dirent *readdir(DIR *dp) { char *_tmp; + size_t reclen; if (!dp || dp->finished) return NULL; @@ -98,14 +99,15 @@ struct dirent *readdir(DIR *dp) } } - _tmp = php_win32_ioutil_w_to_any(dp->fileinfo.cFileName); + _tmp = php_win32_cp_conv_w_to_any(dp->fileinfo.cFileName, PHP_WIN32_CP_IGNORE_LEN, &reclen); if (!_tmp) { /* wide to utf8 failed, should never happen. */ return NULL; } - strlcpy(dp->dent.d_name, _tmp, _MAX_FNAME*4+1); - dp->dent.d_reclen = (unsigned short)strlen(dp->dent.d_name); - free(_tmp); + if (dp->dent.d_name) + free(dp->dent.d_name); + dp->dent.d_name = _tmp; + dp->dent.d_reclen = (unsigned short)reclen; dp->offset++; @@ -118,6 +120,7 @@ struct dirent *readdir(DIR *dp) int readdir_r(DIR *dp, struct dirent *entry, struct dirent **result) { char *_tmp; + size_t reclen; if (!dp || dp->finished) { *result = NULL; @@ -132,15 +135,16 @@ int readdir_r(DIR *dp, struct dirent *entry, struct dirent **result) } } - _tmp = php_win32_ioutil_w_to_any(dp->fileinfo.cFileName); + _tmp = php_win32_cp_conv_w_to_any(dp->fileinfo.cFileName, PHP_WIN32_CP_IGNORE_LEN, &reclen); if (!_tmp) { /* wide to utf8 failed, should never happen. */ result = NULL; return 0; } - strlcpy(dp->dent.d_name, _tmp, _MAX_FNAME*4+1); - dp->dent.d_reclen = (unsigned short)strlen(dp->dent.d_name); - free(_tmp); + if (dp->dent.d_name) + free(dp->dent.d_name); + dp->dent.d_name = _tmp; + dp->dent.d_reclen = (unsigned short)reclen; dp->offset++; @@ -165,6 +169,8 @@ int closedir(DIR *dp) } if (dp->dirw) free(dp->dirw); + if (dp->dent.d_name) + free(dp->dent.d_name); if (dp) free(dp); diff --git a/win32/readdir.h b/win32/readdir.h index 495c36a..aa485fb 100644 --- a/win32/readdir.h +++ b/win32/readdir.h @@ -22,7 +22,7 @@ struct dirent { long d_ino; /* inode (always 1 in WIN32) */ off_t d_off; /* offset to this dirent */ unsigned short d_reclen; /* length of d_name */ - char d_name[_MAX_FNAME*4+1]; /* filename with care about UTF-8 (null terminated) */ + char *d_name; /* null terminated filename in the current encoding, glyph number <= 255 wchar_t's + \0 byte */ }; /* typedef DIR - not the same as Unix */