1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

time: gmt offset; macos syscalls

This commit is contained in:
Alexander Medvednikov
2019-12-31 19:53:15 +01:00
parent 3c17851200
commit 87cff0386c
9 changed files with 63 additions and 33 deletions

View File

@ -330,6 +330,7 @@ pub fn (f mut File) close() {
}
f.opened = false
$if linux {
//$if linux_or_macos {
C.syscall(sys_close, f.fd)
return
}

18
vlib/os/os_darwin.v Normal file
View File

@ -0,0 +1,18 @@
// 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
pub const (
sys_write = 4
sys_open = 5
sys_close = 6
sys_mkdir = 136
sys_creat = 8
sys_open_nocancel = 398
sys_stat64 = 338
)

View File

@ -7,11 +7,20 @@ module os
const (
PROT_READ = 1
PROT_WRITE = 2
MAP_PRIVATE = 0x02
MAP_ANONYMOUS = 0x20
)
pub const (
sys_write = 1
sys_open = 2
sys_close = 3
sys_mkdir = 83
sys_creat = 85
)
/*
// TODO no pub => error
@ -32,7 +41,7 @@ pub fn println(s string) {
fn mmap(start voidptr, len, prot, flags, fd, off int) byteptr {
return syscall6(9, start, len, prot, flags, fd, off) // sys_mmap
}
}
pub fn malloc(n int) byteptr {
println('malloc($n)')
@ -41,7 +50,7 @@ pub fn malloc(n int) byteptr {
}
pub fn free(b byteptr) {
}
*/

View File

@ -6,14 +6,6 @@ pub const (
path_separator = '/'
)
pub const (
sys_write = 1
sys_open = 2
sys_close = 3
sys_mkdir = 83
sys_creat = 85
)
const (
stdin_value = 0
stdout_value = 1
@ -77,6 +69,7 @@ pub fn is_dir(path string) bool {
pub fn open(path string) ?File {
$if linux {
//$if linux_or_macos {
fd := C.syscall(sys_open, path.str, 511)
if fd == -1 {
return error('failed to open file "$path"')
@ -103,8 +96,16 @@ pub fn open(path string) ?File {
// create creates a file at a specified location and returns a writable `File` object.
pub fn create(path string) ?File {
$if linux {
fd := C.syscall(sys_creat, path.str, 511)
//////println('Fd=$fd')
//$if linux_or_macos {
mut fd := 0
println('creat SYS')
$if macos {
fd = C.syscall(sys_open_nocancel, path.str, 0x601, 0x1b6)
}
$else {
fd = C.syscall(sys_creat, path.str, 511)
}
println('fd=$fd')
if fd == -1 {
return error('failed to create file "$path"')
}
@ -134,6 +135,7 @@ pub fn (f mut File) write(s string) {
return
}
$if linux {
//$if linux_or_macos {
C.syscall(sys_write, f.fd, s.str, s.len)
return
}
@ -146,6 +148,7 @@ pub fn (f mut File) writeln(s string) {
if !f.opened {
return
}
//$if linux_or_macos {
$if linux {
snl := s + '\n'
C.syscall(sys_write, f.fd, snl.str, snl.len)