1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

os: remove os_mac.v and os_win.v, fix os.ls() on Windows

This commit is contained in:
Alexander Medvednikov 2019-06-30 14:55:48 +02:00
parent b0c844415d
commit 820aa3d3b3
4 changed files with 85 additions and 109 deletions

View File

@ -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'

View File

@ -5,12 +5,21 @@
module os
#include <sys/stat.h>
#include <signal.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
//#include <execinfo.h> // 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) ;
*/
}

View File

@ -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 <execinfo.h> // for backtrace_symbols_fd
#include <signal.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
// 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) ;
*/
}

View File

@ -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) {
}