From fa24a0cec5cbdff9a36aaf32cca17559f5177895 Mon Sep 17 00:00:00 2001 From: jilio Date: Wed, 31 Jul 2019 15:32:00 +0700 Subject: [PATCH] os: fix is_dir --- vlib/os/const.v | 6 ++++++ vlib/os/os.v | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/vlib/os/const.v b/vlib/os/const.v index 584a539347..25c5f7772c 100644 --- a/vlib/os/const.v +++ b/vlib/os/const.v @@ -80,6 +80,12 @@ const ( O_TRUNC = 128 // truncate regular writable file when opened. ) +// ref: http://www.ccfit.nsu.ru/~deviv/courses/unix/unix/ng7c229.html +const ( + S_IFMT = 0xF000 // type of file + S_IFDIR = 0x4000 // directory +) + // Windows const( INVALID_HANDLE_VALUE = -1 diff --git a/vlib/os/os.v b/vlib/os/os.v index c149bfb529..c1d27347c3 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -718,7 +718,8 @@ pub fn is_dir(path string) bool { if C.stat(cstr, &statbuf) != 0 { return false } - return statbuf.st_mode & S_IFMT == S_IFDIR + // ref: https://code.woboq.org/gcc/include/sys/stat.h.html + return (statbuf.st_mode & S_IFMT) == S_IFDIR } }