Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions builtin-functions/kphp-light/stdlib/file-functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ function file_exists ($name ::: string) ::: bool;

function file ($name ::: string) ::: string[] | false;

function is_dir ($name ::: string) ::: bool;

function is_file ($name ::: string) ::: bool;

function fgets ($stream ::: mixed, $length ::: int = -1) ::: string | false;
Expand All @@ -66,8 +68,6 @@ function filectime ($name ::: string) ::: int | false;
/** @kphp-extern-func-info stub generation-required */
function filemtime ($name ::: string) ::: int | false;
/** @kphp-extern-func-info stub generation-required */
function is_dir ($name ::: string) ::: bool;
/** @kphp-extern-func-info stub generation-required */
function is_readable ($name ::: string) ::: bool;
/** @kphp-extern-func-info stub generation-required */
function mkdir ($name ::: string, $mode ::: int = 0777, $recursive ::: bool = false) ::: bool;
Expand Down
9 changes: 9 additions & 0 deletions runtime-light/stdlib/file/file-system-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ inline Optional<array<string>> f$file(const string& name) noexcept {
return result;
}

inline bool f$is_dir(const string& name) noexcept {
struct stat stat_buf {};
// TODO: the semantics in PHP are different: PHP expects stat
if (!k2::lstat(name.c_str(), std::addressof(stat_buf)).has_value()) {
return false;
}
return S_ISDIR(stat_buf.st_mode);
}

inline bool f$is_file(const string& name) noexcept {
struct stat stat_buf {};
// TODO: the semantics in PHP are different: PHP expects stat
Expand Down
2 changes: 2 additions & 0 deletions tests/phpt/dl/473_file_for_k2.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
var_dump (basename ('/etc/sudoers.d', '.d'));

$filename = '/tmp/' . rand(1, 2e9);
var_dump (is_dir ('/tmp'));
var_dump (is_dir ($filename));
Comment thread
apolyakov marked this conversation as resolved.
var_dump (is_file ($filename));
// var_dump ($filename);
$file = fopen ($filename, "w");
Expand Down
Loading