1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/os/os_mac.v
2019-06-23 09:22:49 +02:00

72 lines
1.4 KiB
Go

// 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>
#include <signal.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
// import darwin
fn log(s string) {
}
fn is_dir(path string) bool {
# struct stat statbuf;
cstr := path.cstr()
# if (stat(cstr, &statbuf) != 0)
{
return false
}
# return S_ISDIR(statbuf.st_mode);
return false
}
fn chdir(path string) {
C.chdir(path.cstr())
}
fn getwd() string {
cwd := malloc(1024)
# if (getcwd(cwd, 1024)) return tos2(cwd);
return ''
}
fn ls(path string) []string {
mut res := []string
# DIR *dir;
# struct dirent *ent;
# if ((dir = opendir (path.str)) == NULL)
{
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
}
# }
# closedir (dir);
// res.sort()
// println('sorted res')
// print_strings(res)
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) ;
}