diff --git a/compiler/main.v b/compiler/main.v index 4dea930c40..1800fefefd 100644 --- a/compiler/main.v +++ b/compiler/main.v @@ -489,7 +489,7 @@ mut args := '' a << '-lm -ldl -lpthread' } // Find clang executable - fast_clang := '/usr/local/Cellar/llvm/8.0.0/bin/clang' + fast_clang := 'ff'///usr/local/Cellar/llvm/8.0.0/bin/clang' args := a.join(' ') mut cmd := if os.file_exists(fast_clang) { '$fast_clang $args' diff --git a/vlib/os/os.v b/vlib/os/os.v index 47e3afeafa..31dff20c00 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -5,12 +5,21 @@ module os #include +#include +#include +#include +#include +//#include // for backtrace_symbols_fd const ( args = []string MAX_PATH = 4096 ) +const ( + FILE_ATTRIBUTE_DIRECTORY = 16 // Windows +) + struct FILE { } @@ -490,3 +499,78 @@ pub fn getexepath() string { return '' } } + +pub fn is_dir(path string) bool { + $if windows { + val := int(C.GetFileAttributes(path.cstr())) + return val &FILE_ATTRIBUTE_DIRECTORY > 0 + } + $else { + statbuf := C.stat{} + cstr := path.cstr() + if C.stat(cstr, &statbuf) != 0 { + return false + } + return statbuf.st_mode & S_IFMT == S_IFDIR + } +} + +fn chdir(path string) { + $if windows { + C._chdir(path.cstr()) + } + $else { + C.chdir(path.cstr()) + } +} + +pub fn getwd() string { + buf := malloc(512) + $if windows { + if C._getcwd(buf, 512) == 0 { + return '' + } + } + $else { + if C.getcwd(buf, 512) == 0 { + return '' + } + } + return string(buf) +} + +pub fn ls(path string) []string { + mut res := []string + dir := C.opendir(path.str) + if isnil(dir) { + println('ls() couldnt open dir "$path"') + print_c_errno() + return res + } + mut ent := &C.dirent{!} + for { + ent = C.readdir(dir) + if isnil(ent) { + break + } + name := tos_clone(ent.d_name) + if name != '.' && name != '..' && name != '' { + res << name + } + } + C.closedir(dir) + return res +} + +fn log(s string) { +} + +fn print_backtrace() { +/* + # void *buffer[100]; + nptrs := 0 + # nptrs = backtrace(buffer, 100); + # printf("%d!!\n", nptrs); + # backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO) ; +*/ +} diff --git a/vlib/os/os_mac.v b/vlib/os/os_mac.v deleted file mode 100644 index b3990c688e..0000000000 --- a/vlib/os/os_mac.v +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright (c) 2019 Alexander Medvednikov. All rights reserved. -// Use of this source code is governed by an MIT license -// that can be found in the LICENSE file. - -module os - -//#include // for backtrace_symbols_fd -#include -#include -#include -#include -// import darwin -fn log(s string) { -} - - -pub fn is_dir(path string) bool { - statbuf := C.stat{} - cstr := path.cstr() - if C.stat(cstr, &statbuf) != 0 { - return false - } - return statbuf.st_mode & S_IFMT == S_IFDIR -} - -fn chdir(path string) { - C.chdir(path.cstr()) -} - -pub fn getwd() string { - cwd := malloc(512) - if C.getcwd(cwd, 512) == 0 { - return '' - } - return string(cwd) -} - -pub fn ls(path string) []string { - mut res := []string - dir := C.opendir(path.str) - if isnil(dir) { - println('ls() couldnt open dir "$path"') - print_c_errno() - return res - } - mut ent := &C.dirent{!} - for { - ent = C.readdir(dir) - if isnil(ent) { - break - } - name := tos_clone(ent.d_name) - if name != '.' && name != '..' && name != '' { - res << name - } - } - C.closedir(dir) - return res -} - -fn print_backtrace() { -/* - # void *buffer[100]; - nptrs := 0 - # nptrs = backtrace(buffer, 100); - # printf("%d!!\n", nptrs); - # backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO) ; -*/ -} - diff --git a/vlib/os/os_win.v b/vlib/os/os_win.v deleted file mode 100644 index bbb18861c9..0000000000 --- a/vlib/os/os_win.v +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2019 Alexander Medvednikov. All rights reserved. -// Use of this source code is governed by an MIT license -// that can be found in the LICENSE file. - -module os - -pub fn ls(path string) []string { - mut res := []string - return res -} - -pub fn getwd() string { - mut buffer := malloc(512) - - buffer = C._getcwd(0, 0) - // A NULL return value indicates an error - if isnil(buffer) { - return '' - } - return string(buffer) -} - -const ( - FILE_ATTRIBUTE_DIRECTORY = 16 -) - -fn is_dir(path string) bool { - val := int(C.GetFileAttributes(path.cstr())) - return val &FILE_ATTRIBUTE_DIRECTORY > 0 -} - -fn chdir(path string) { - C._chdir(path.cstr()) -} - -fn log(s string) { -} -