summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2017-10-09 13:07:40 +0200
committerAnatol Belski <ab@php.net>2017-10-09 13:12:40 +0200
commitdc3b9fe619ca36ddb1f1948c66fc09a500dedc2f (patch)
tree58b6831b659d4296f110a4270b7a9d169a582320
parentac1fd769ad2c69f40007e5d679c6c61631eaec44 (diff)
downloadphp-git-dc3b9fe619ca36ddb1f1948c66fc09a500dedc2f.tar.gz
Fix ftok() multibyte path support
-rw-r--r--win32/ftok.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/win32/ftok.c b/win32/ftok.c
index eb926b1030..64c430b771 100644
--- a/win32/ftok.c
+++ b/win32/ftok.c
@@ -21,24 +21,33 @@
#include <windows.h>
#include <sys/stat.h>
+#include "ioutil.h"
PHPAPI key_t
ftok(const char *pathname, int proj_id)
{
HANDLE fh;
- struct stat st;
+ struct _stat st;
BY_HANDLE_FILE_INFORMATION bhfi;
key_t ret;
+ PHP_WIN32_IOUTIL_INIT_W(pathname)
- if (stat(pathname, &st) < 0) {
+ if (!pathw) {
return (key_t)-1;
}
- if ((fh = CreateFile(pathname, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE) {
+ if (_wstat(pathw, &st) < 0) {
+ PHP_WIN32_IOUTIL_CLEANUP_W()
+ return (key_t)-1;
+ }
+
+ if ((fh = CreateFileW(pathw, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE) {
+ PHP_WIN32_IOUTIL_CLEANUP_W()
return (key_t)-1;
}
if (!GetFileInformationByHandle(fh, &bhfi)) {
+ PHP_WIN32_IOUTIL_CLEANUP_W()
CloseHandle(fh);
return (key_t)-1;
}
@@ -46,6 +55,7 @@ ftok(const char *pathname, int proj_id)
ret = (key_t) ((proj_id & 0xff) << 24 | (st.st_dev & 0xff) << 16 | ((bhfi.nFileIndexLow | (__int64)bhfi.nFileIndexHigh << 32) & 0xffff));
CloseHandle(fh);
+ PHP_WIN32_IOUTIL_CLEANUP_W()
return ret;
}