vfmt: fix `sizeof(C.Type)`
parent
e1eb9c4ff1
commit
4cb9e651a6
|
@ -6,14 +6,13 @@ import strings
|
|||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
pub const (
|
||||
path_separator = '/'
|
||||
path_delimiter = ':'
|
||||
)
|
||||
|
||||
const (
|
||||
stdin_value = 0
|
||||
stdin_value = 0
|
||||
stdout_value = 1
|
||||
stderr_value = 2
|
||||
)
|
||||
|
@ -28,11 +27,14 @@ mut:
|
|||
}
|
||||
|
||||
fn C.uname(name voidptr) int
|
||||
fn C.symlink(charptr, charptr) int
|
||||
|
||||
fn C.symlink(arg_1, arg_2 charptr) int
|
||||
|
||||
pub fn uname() Uname {
|
||||
mut u := Uname{}
|
||||
d := &C.utsname( malloc(int(sizeof(C.utsname))) )
|
||||
utsize := sizeof(C.utsname)
|
||||
x := malloc(int(utsize))
|
||||
d := &C.utsname(x)
|
||||
if C.uname(d) == 0 {
|
||||
u.sysname = cstring_to_vstring(byteptr(d.sysname))
|
||||
u.nodename = cstring_to_vstring(byteptr(d.nodename))
|
||||
|
@ -46,11 +48,10 @@ pub fn uname() Uname {
|
|||
|
||||
fn init_os_args(argc int, argv &&byte) []string {
|
||||
mut args := []string{}
|
||||
//mut args := []string(make(0, argc, sizeof(string)))
|
||||
//mut args := []string{len:argc}
|
||||
// mut args := []string(make(0, argc, sizeof(string)))
|
||||
// mut args := []string{len:argc}
|
||||
for i in 0 .. argc {
|
||||
|
||||
//args [i] = string(argv[i])
|
||||
// args [i] = string(argv[i])
|
||||
args << string(argv[i])
|
||||
}
|
||||
return args
|
||||
|
@ -91,13 +92,10 @@ pub fn is_dir(path string) bool {
|
|||
return res
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
pub fn (mut f File) fseek(pos, mode int) {
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// mkdir creates a new directory with the specified path.
|
||||
pub fn mkdir(path string) ?bool {
|
||||
if path == '.' {
|
||||
|
@ -109,8 +107,8 @@ pub fn mkdir(path string) ?bool {
|
|||
k = 1
|
||||
}
|
||||
*/
|
||||
apath := os.real_path(path)
|
||||
/*
|
||||
apath := real_path(path)
|
||||
/*
|
||||
$if linux {
|
||||
$if !android {
|
||||
ret := C.syscall(sys_mkdir, apath.str, 511)
|
||||
|
@ -120,8 +118,11 @@ pub fn mkdir(path string) ?bool {
|
|||
return true
|
||||
}
|
||||
}
|
||||
*/
|
||||
r := unsafe {C.mkdir(charptr(apath.str), 511)}
|
||||
*/
|
||||
r := unsafe {
|
||||
C.mkdir(charptr(apath.str), 511)
|
||||
}
|
||||
|
||||
if r == -1 {
|
||||
return error(posix_get_error_msg(C.errno))
|
||||
}
|
||||
|
@ -142,10 +143,10 @@ pub fn exec(cmd string) ?Result {
|
|||
mut res := strings.new_builder(1024)
|
||||
for C.fgets(charptr(buf), 4096, f) != 0 {
|
||||
bufbp := byteptr(buf)
|
||||
res.write_bytes( bufbp, vstrlen(bufbp) )
|
||||
res.write_bytes(bufbp, vstrlen(bufbp))
|
||||
}
|
||||
soutput := res.str()
|
||||
//res.free()
|
||||
// res.free()
|
||||
exit_code := vpclose(f)
|
||||
// if exit_code != 0 {
|
||||
// return error(res)
|
||||
|
@ -174,14 +175,14 @@ pub fn (mut f File) close() {
|
|||
return
|
||||
}
|
||||
f.opened = false
|
||||
/*
|
||||
/*
|
||||
$if linux {
|
||||
$if !android {
|
||||
C.syscall(sys_close, f.fd)
|
||||
return
|
||||
}
|
||||
}
|
||||
*/
|
||||
*/
|
||||
C.fflush(f.cfile)
|
||||
C.fclose(f.cfile)
|
||||
}
|
||||
|
|
|
@ -914,7 +914,11 @@ pub fn (mut f Fmt) expr(node ast.Expr) {
|
|||
if node.is_type {
|
||||
f.write('sizeof(')
|
||||
if node.type_name != '' {
|
||||
f.write(f.short_module(node.type_name))
|
||||
if f.is_external_name(node.type_name) {
|
||||
f.write(node.type_name)
|
||||
} else {
|
||||
f.write(f.short_module(node.type_name))
|
||||
}
|
||||
} else {
|
||||
f.write(f.type_to_str(node.typ))
|
||||
}
|
||||
|
@ -1732,3 +1736,13 @@ pub fn (mut f Fmt) const_decl(it ast.ConstDecl) {
|
|||
f.indent--
|
||||
f.writeln(')\n')
|
||||
}
|
||||
|
||||
fn (mut f Fmt) is_external_name(name string) bool {
|
||||
if name.len > 2 && name[0]==`C` && name[1]==`.` {
|
||||
return true
|
||||
}
|
||||
if name.len > 3 && name[0]==`J` && name[1]==`S` && name[2] == `.` {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue