Skip to content

Commit 0494d90

Browse files
committed
Merge branch 'PHP-7.2'
* PHP-7.2: Fix ftok() multibyte path support
2 parents fcccb0d + a51c542 commit 0494d90

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

win32/ftok.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,41 @@
2121
#include <windows.h>
2222
#include <sys/stat.h>
2323

24+
#include "ioutil.h"
2425

2526
PHP_WIN32_IPC_API key_t
2627
ftok(const char *pathname, int proj_id)
2728
{/*{{{*/
2829
HANDLE fh;
29-
struct stat st;
30+
struct _stat st;
3031
BY_HANDLE_FILE_INFORMATION bhfi;
3132
key_t ret;
33+
PHP_WIN32_IOUTIL_INIT_W(pathname)
3234

33-
if (stat(pathname, &st) < 0) {
35+
if (!pathw) {
3436
return (key_t)-1;
3537
}
3638

37-
if ((fh = CreateFile(pathname, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE) {
39+
if (_wstat(pathw, &st) < 0) {
40+
PHP_WIN32_IOUTIL_CLEANUP_W()
41+
return (key_t)-1;
42+
}
43+
44+
if ((fh = CreateFileW(pathw, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE) {
45+
PHP_WIN32_IOUTIL_CLEANUP_W()
3846
return (key_t)-1;
3947
}
4048

4149
if (!GetFileInformationByHandle(fh, &bhfi)) {
50+
PHP_WIN32_IOUTIL_CLEANUP_W()
4251
CloseHandle(fh);
4352
return (key_t)-1;
4453
}
4554

4655
ret = (key_t) ((proj_id & 0xff) << 24 | (st.st_dev & 0xff) << 16 | ((bhfi.nFileIndexLow | (__int64)bhfi.nFileIndexHigh << 32) & 0xffff));
4756

4857
CloseHandle(fh);
58+
PHP_WIN32_IOUTIL_CLEANUP_W()
4959

5060
return ret;
5161
}/*}}}*/

0 commit comments

Comments
 (0)