Files
kraken/stdlib/os.krak
2018-05-22 19:43:54 -04:00

33 lines
898 B
Plaintext

import str:*
import mem:*
import io:*
fun system(call_string: str):int {
var c_call_string = call_string.toCharArray()
var result = system(c_call_string)
delete(c_call_string)
return result
}
ext fun system(call_string: *char): int
ext fun exit(code: int):void
fun exit() exit(0)
ext fun popen(command: *char, mode: *char): *void
ext fun pclose(file: *void): int
fun from_system_command(command: str, line_size: int): str {
var command_string = command.toCharArray()
defer delete(command_string)
var p = popen(command_string, "r")
var to_ret = get_line(line_size, p)
pclose(p)
return to_ret
}
fun get_time(): long { return string_to_num<long>(from_system_command(str("date +%s"), 50)); }
fun split(time: long, split_label: *char): long {
var new_time = get_time()
print(str(split_label) + ": ")
println(new_time - time)
return new_time
}