Skip to content

Commit 773957c

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #78386: fstat mode has unexpected value on PHP 7.4
2 parents 4867864 + c03114e commit 773957c

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

ext/standard/tests/file/bug78386.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #78386 (fstat mode has unexpected value on PHP 7.4)
3+
--SKIPIF--
4+
<?php
5+
if (substr(PHP_OS, 0, 3) != 'WIN') die("skip this test is for Windows platforms only");
6+
?>
7+
--FILE--
8+
<?php
9+
$handle = popen('dir', 'r');
10+
$stat = fstat($handle);
11+
var_dump(decoct($stat['mode']));
12+
?>
13+
--EXPECT--
14+
string(5) "10666"

win32/ioutil.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,20 @@ static int php_win32_ioutil_fstat_int(HANDLE h, php_win32_ioutil_stat_t *buf, co
942942
}
943943

944944
if ((data->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == 0) {
945-
buf->st_mode |= is_dir ? (S_IFDIR|S_IEXEC|(S_IEXEC>>3)|(S_IEXEC>>6)) : S_IFREG;
945+
if (is_dir) {
946+
buf->st_mode |= (S_IFDIR|S_IEXEC|(S_IEXEC>>3)|(S_IEXEC>>6));
947+
} else {
948+
switch (GetFileType(h)) {
949+
case FILE_TYPE_CHAR:
950+
buf->st_mode |= S_IFCHR;
951+
break;
952+
case FILE_TYPE_PIPE:
953+
buf->st_mode |= S_IFIFO;
954+
break;
955+
default:
956+
buf->st_mode |= S_IFREG;
957+
}
958+
}
946959
buf->st_mode |= (data->dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? (S_IREAD|(S_IREAD>>3)|(S_IREAD>>6)) : (S_IREAD|(S_IREAD>>3)|(S_IREAD>>6)|S_IWRITE|(S_IWRITE>>3)|(S_IWRITE>>6));
947960
}
948961

0 commit comments

Comments
 (0)