2019-06-23 04:21:30 +02:00
|
|
|
// 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.
|
|
|
|
|
2019-06-22 20:20:28 +02:00
|
|
|
module os
|
|
|
|
|
2019-06-24 15:53:29 +02:00
|
|
|
//#include <execinfo.h> // for backtrace_symbols_fd
|
2019-06-22 20:20:28 +02:00
|
|
|
#include <signal.h>
|
2019-06-24 15:53:29 +02:00
|
|
|
#include <unistd.h>
|
2019-06-22 20:20:28 +02:00
|
|
|
#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() {
|
2019-06-24 15:53:29 +02:00
|
|
|
/*
|
2019-06-22 20:20:28 +02:00
|
|
|
# void *buffer[100];
|
|
|
|
nptrs := 0
|
|
|
|
# nptrs = backtrace(buffer, 100);
|
|
|
|
# printf("%d!!\n", nptrs);
|
|
|
|
# backtrace_symbols_fd(buffer, nptrs, STDOUT_FILENO) ;
|
2019-06-24 15:53:29 +02:00
|
|
|
*/
|
2019-06-22 20:20:28 +02:00
|
|
|
}
|
|
|
|
|