mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Added pull request #1189: Fix os::native_is_{file,dir} bug. Add tests.
This commit is contained in:
@@ -95,7 +95,7 @@ fn bool native_is_file(String path)
|
|||||||
$case env::DARWIN:
|
$case env::DARWIN:
|
||||||
$case env::LINUX:
|
$case env::LINUX:
|
||||||
Stat stat;
|
Stat stat;
|
||||||
return @ok(native_stat(&stat, path)) && stat.st_mode & libc::S_IFREG;
|
return @ok(native_stat(&stat, path)) && libc_S_ISTYPE(stat.st_mode, libc::S_IFREG);
|
||||||
$default:
|
$default:
|
||||||
File! f = file::open(path, "r");
|
File! f = file::open(path, "r");
|
||||||
defer (void)f.close();
|
defer (void)f.close();
|
||||||
@@ -107,7 +107,7 @@ fn bool native_is_dir(String path)
|
|||||||
{
|
{
|
||||||
$if env::DARWIN || env::LINUX:
|
$if env::DARWIN || env::LINUX:
|
||||||
Stat stat;
|
Stat stat;
|
||||||
return @ok(native_stat(&stat, path)) && stat.st_mode & libc::S_IFDIR;
|
return @ok(native_stat(&stat, path)) && libc_S_ISTYPE(stat.st_mode, libc::S_IFDIR);
|
||||||
$else
|
$else
|
||||||
return native_file_or_dir_exists(path) && !native_is_file(path);
|
return native_file_or_dir_exists(path) && !native_is_file(path);
|
||||||
$endif
|
$endif
|
||||||
|
|||||||
@@ -360,6 +360,7 @@ const int EOF = -1;
|
|||||||
const int FOPEN_MAX = 20;
|
const int FOPEN_MAX = 20;
|
||||||
const int FILENAME_MAX = 1024;
|
const int FILENAME_MAX = 1024;
|
||||||
|
|
||||||
|
macro bool libc_S_ISTYPE(value, mask) @builtin => (value & S_IFMT) == mask;
|
||||||
const S_IFMT = 0o170000; // type of file mask
|
const S_IFMT = 0o170000; // type of file mask
|
||||||
const S_IFIFO = 0o010000; // named pipe (fifo)
|
const S_IFIFO = 0o010000; // named pipe (fifo)
|
||||||
const S_IFCHR = 0o020000; // character special
|
const S_IFCHR = 0o020000; // character special
|
||||||
|
|||||||
16
test/unit/stdlib/io/fileinfo.c3
Normal file
16
test/unit/stdlib/io/fileinfo.c3
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
module std::io::fileinfo @test;
|
||||||
|
import std::io::os;
|
||||||
|
|
||||||
|
fn void test_native_is_file() @if(env::LINUX || env::DARWIN)
|
||||||
|
{
|
||||||
|
assert(!os::native_is_file("/dev/loop0"));
|
||||||
|
assert(!os::native_is_file("/dev/null"));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn void test_native_is_dir() @if(env::LINUX || env::DARWIN)
|
||||||
|
{
|
||||||
|
assert(os::native_is_dir("/"));
|
||||||
|
assert(!os::native_is_file("/"));
|
||||||
|
assert(!os::native_is_dir("/dev/loop0"));
|
||||||
|
assert(!os::native_is_dir("/dev/null"));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user