1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/os/os_nix.v
Alexander Medvednikov be141d9c5f os: Windows fixes
2019-08-17 02:09:36 +03:00

42 lines
712 B
Go

module os
#include <dirent.h>
#include <unistd.h>
const (
PathSeparator = '/'
)
// get_error_msg return error code representation in string.
pub fn get_error_msg(code int) string {
_ptr_text := C.strerror(code) // voidptr?
if _ptr_text == 0 {
return ''
}
return tos(_ptr_text, C.strlen(_ptr_text))
}
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
}