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

fmt: add a space around single-line unsafe expressions (#7505)

This commit is contained in:
spaceface
2020-12-23 19:13:42 +01:00
committed by GitHub
parent b27f5c378c
commit 214290d55b
22 changed files with 108 additions and 108 deletions

View File

@ -82,8 +82,8 @@ pub fn environ() map[string]string {
C.FreeEnvironmentStringsW(estrings)
} $else {
e := &charptr(C.environ)
for i := 0; !isnil(unsafe {e[i]}); i++ {
eline := unsafe {cstring_to_vstring(byteptr(e[i]))}
for i := 0; !isnil(unsafe { e[i] }); i++ {
eline := unsafe { cstring_to_vstring(byteptr(e[i])) }
eq_index := eline.index_byte(`=`)
if eq_index > 0 {
res[eline[0..eq_index]] = eline[eq_index + 1..]

View File

@ -14,7 +14,7 @@ pub fn fd_write(fd int, s string) {
return
}
remaining = remaining - written
sp = unsafe {sp + written}
sp = unsafe { sp + written }
}
}

View File

@ -32,7 +32,7 @@ pub:
// it supports windows for regular files but it doesn't matter if you use owner, group or others when checking permissions on windows
pub fn inode(path string) FileMode {
mut attr := C.stat{}
unsafe {C.stat(charptr(path.str), &attr)}
unsafe { C.stat(charptr(path.str), &attr) }
mut typ := FileType.regular
if attr.st_mode & u32(C.S_IFMT) == u32(C.S_IFDIR) {
typ = .directory

View File

@ -160,7 +160,7 @@ pub fn cp(src string, dst string) ? {
}
}
from_attr := C.stat{}
unsafe {C.stat(charptr(src.str), &from_attr)}
unsafe { C.stat(charptr(src.str), &from_attr) }
if C.chmod(charptr(dst.str), from_attr.st_mode) < 0 {
return error_with_code('failed to set permissions for $dst', int(-1))
}
@ -580,7 +580,7 @@ pub fn executable() string {
eprintln('os.executable() failed at reading /proc/self/exe to get exe path')
return executable_fallback()
}
return unsafe {result.vstring()}
return unsafe { result.vstring() }
}
$if windows {
max := 512
@ -617,14 +617,14 @@ pub fn executable() string {
eprintln('os.executable() failed at calling proc_pidpath with pid: $pid . proc_pidpath returned $ret ')
return executable_fallback()
}
return unsafe {result.vstring()}
return unsafe { result.vstring() }
}
$if freebsd {
mut result := vcalloc(max_path_len)
mib := [1 /* CTL_KERN */, 14 /* KERN_PROC */, 12 /* KERN_PROC_PATHNAME */, -1]
size := max_path_len
unsafe {C.sysctl(mib.data, 4, result, &size, 0, 0)}
return unsafe {result.vstring()}
unsafe { C.sysctl(mib.data, 4, result, &size, 0, 0) }
return unsafe { result.vstring() }
}
// "Sadly there is no way to get the full path of the executed file in OpenBSD."
$if openbsd {
@ -640,7 +640,7 @@ pub fn executable() string {
eprintln('os.executable() failed at reading /proc/curproc/exe to get exe path')
return executable_fallback()
}
return unsafe {result.vstring_with_len(count)}
return unsafe { result.vstring_with_len(count) }
}
$if dragonfly {
mut result := vcalloc(max_path_len)
@ -649,7 +649,7 @@ pub fn executable() string {
eprintln('os.executable() failed at reading /proc/curproc/file to get exe path')
return executable_fallback()
}
return unsafe {result.vstring_with_len(count)}
return unsafe { result.vstring_with_len(count) }
}
return executable_fallback()
}
@ -668,7 +668,7 @@ pub fn is_dir(path string) bool {
return false
} $else {
statbuf := C.stat{}
if unsafe {C.stat(charptr(path.str), &statbuf)} != 0 {
if unsafe { C.stat(charptr(path.str), &statbuf) } != 0 {
return false
}
// ref: https://code.woboq.org/gcc/include/sys/stat.h.html
@ -713,7 +713,7 @@ pub fn getwd() string {
if C.getcwd(charptr(buf), 512) == 0 {
return ''
}
return unsafe {buf.vstring()}
return unsafe { buf.vstring() }
}
}
@ -736,7 +736,7 @@ pub fn real_path(fpath string) string {
return fpath
}
}
res := unsafe {fullpath.vstring()}
res := unsafe { fullpath.vstring() }
return normalize_drive_letter(res)
}
@ -759,7 +759,7 @@ fn normalize_drive_letter(path string) string {
// signal will assign `handler` callback to be called when `signum` signal is recieved.
pub fn signal(signum int, handler voidptr) {
unsafe {C.signal(signum, handler)}
unsafe { C.signal(signum, handler) }
}
// fork will fork the current system process and return the pid of the fork.
@ -791,7 +791,7 @@ pub fn wait() int {
pub fn file_last_mod_unix(path string) int {
attr := C.stat{}
// # struct stat attr;
unsafe {C.stat(charptr(path.str), &attr)}
unsafe { C.stat(charptr(path.str), &attr) }
// # stat(path.str, &attr);
return attr.st_mtime
// # return attr.st_mtime ;

View File

@ -52,7 +52,7 @@ fn init_os_args(argc int, argv &&byte) []string {
// mut args := []string{len:argc}
for i in 0 .. argc {
// args [i] = argv[i].vstring()
unsafe {args << byteptr(argv[i]).vstring()}
unsafe { args << byteptr(argv[i]).vstring() }
}
return args
}
@ -122,7 +122,7 @@ pub fn mkdir(path string) ?bool {
}
}
*/
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))
}

View File

@ -78,7 +78,7 @@ mut:
fn init_os_args_wide(argc int, argv &byteptr) []string {
mut args := []string{}
for i in 0 .. argc {
args << string_from_wide(unsafe {&u16(argv[i])})
args << string_from_wide(unsafe { &u16(argv[i]) })
}
return args
}