mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
Replace all remaining C code with V in the compiler and vlib (hoorah!)
This commit is contained in:
21
os/os.v
21
os/os.v
@ -26,17 +26,30 @@ import const (
|
||||
SEEK_END
|
||||
SA_SIGINFO
|
||||
SIGSEGV
|
||||
|
||||
S_IFMT
|
||||
S_IFDIR
|
||||
)
|
||||
|
||||
struct C.stat {
|
||||
st_size int
|
||||
st_mode int
|
||||
}
|
||||
|
||||
struct C.DIR {
|
||||
|
||||
}
|
||||
|
||||
struct C.dirent {
|
||||
d_name byteptr
|
||||
|
||||
}
|
||||
|
||||
struct C.sigaction {
|
||||
mut:
|
||||
sa_mask int
|
||||
sa_sigaction int
|
||||
sa_flags int
|
||||
mut:
|
||||
sa_mask int
|
||||
sa_sigaction int
|
||||
sa_flags int
|
||||
}
|
||||
|
||||
fn C.getline(voidptr, voidptr, voidptr) int
|
||||
|
49
os/os_mac.v
49
os/os_mac.v
@ -13,15 +13,14 @@ module os
|
||||
fn log(s string) {
|
||||
}
|
||||
|
||||
fn is_dir(path string) bool {
|
||||
# struct stat statbuf;
|
||||
|
||||
pub fn is_dir(path string) bool {
|
||||
statbuf := C.stat{}
|
||||
cstr := path.cstr()
|
||||
# if (stat(cstr, &statbuf) != 0)
|
||||
{
|
||||
if C.stat(cstr, &statbuf) != 0 {
|
||||
return false
|
||||
}
|
||||
# return S_ISDIR(statbuf.st_mode);
|
||||
return false
|
||||
return statbuf.st_mode & S_IFMT == S_IFDIR
|
||||
}
|
||||
|
||||
fn chdir(path string) {
|
||||
@ -29,35 +28,33 @@ fn chdir(path string) {
|
||||
}
|
||||
|
||||
pub fn getwd() string {
|
||||
cwd := malloc(1024)
|
||||
# if (getcwd(cwd, 1024)) return tos2(cwd);
|
||||
return ''
|
||||
cwd := malloc(512)
|
||||
if C.getcwd(cwd, 512) == 0 {
|
||||
return ''
|
||||
}
|
||||
return string(cwd)
|
||||
}
|
||||
|
||||
pub fn ls(path string) []string {
|
||||
mut res := []string
|
||||
# DIR *dir;
|
||||
# struct dirent *ent;
|
||||
# if ((dir = opendir (path.str)) == NULL)
|
||||
{
|
||||
dir := C.opendir(path.str)
|
||||
if isnil(dir) {
|
||||
println('ls() couldnt open dir "$path"')
|
||||
print_c_errno()
|
||||
return res
|
||||
}
|
||||
// print all the files and directories within directory */
|
||||
# while ((ent = readdir (dir)) != NULL) {
|
||||
name := ''
|
||||
# name = tos_clone(ent->d_name);//, strlen(ent->d_name));
|
||||
// # printf ("printf ls() %s\n", ent->d_name);
|
||||
// println(name)
|
||||
if name != '.' && name != '..' && name != '' {
|
||||
res << name
|
||||
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
|
||||
}
|
||||
}
|
||||
# }
|
||||
# closedir (dir);
|
||||
// res.sort()
|
||||
// println('sorted res')
|
||||
// print_strings(res)
|
||||
C.closedir(dir)
|
||||
return res
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user