Skip to content

Commit

Permalink
os: vfmt all of os .v files, add it to v test-cleancode with no e…
Browse files Browse the repository at this point in the history
…xceptions
  • Loading branch information
spytheman committed Dec 16, 2020
1 parent 6a74058 commit 1ee5764
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 33 deletions.
16 changes: 2 additions & 14 deletions cmd/tools/vtest-cleancode.v
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const (
'cmd/v/v.v',
'vlib/builtin/array.v',
'vlib/builtin/map.v',
'vlib/os/file.c.v',
'vlib/math/bits/bits.v',
'vlib/time/time.v',
'vlib/term/colors.v',
Expand Down Expand Up @@ -58,19 +57,8 @@ const (
'vlib/v/vet/',
'vlib/v/vmod/',
'vlib/gg/gg.v',
'vlib/os/const.v',
'vlib/os/const_windows.c.v',
'vlib/os/environment.c.v',
'vlib/os/environment_test.v',
'vlib/os/inode.c.v',
'vlib/os/inode_test.v',
'vlib/os/os.v',
'vlib/os/os_c.v',
'vlib/os/os_darwin.c.v',
'vlib/os/os_linux.c.v',
'vlib/os/os_nix.c.v',
'vlib/os/os_test.v',
'vlib/os/os_windows.c.v',
'vlib/os/',
'vlib/time/',
]
)

Expand Down
3 changes: 1 addition & 2 deletions vlib/os/cmdline/cmdline.v
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ pub fn option(args []string, param string, def string) string {
for arg in args {
if found {
return arg
}
else if param == arg {
} else if param == arg {
found = true
}
}
Expand Down
22 changes: 11 additions & 11 deletions vlib/os/const_nix.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module os

// File modes
const (
o_rdonly = 000000000 // open the file read-only.
o_wronly = 000000001 // open the file write-only.
o_rdwr = 000000002 // open the file read-write.
o_create = 000000100 // create a new file if none exists.
o_binary = 000008000 // input and output is not translated.
o_excl = 000000200 // used with o_create, file must not exist.
o_noctty = 000000400 // if file is terminal, don't make it the controller terminal
o_trunc = 000001000 // truncate regular writable file when opened.
o_append = 000002000 // append data to the file when writing.
o_nonblock = 000004000 // prevents blocking when opening files
o_sync = 000010000 // open for synchronous I/O.
o_rdonly = 0o00000000 // open the file read-only.
o_wronly = 0o00000001 // open the file write-only.
o_rdwr = 0o00000002 // open the file read-write.
o_binary = 0o00000000 // input and output is not translated; the default on unix
o_create = 0o00000100 // create a new file if none exists.
o_excl = 0o00000200 // used with o_create, file must not exist.
o_noctty = 0o00000400 // if file is terminal, don't make it the controller terminal
o_trunc = 0o00001000 // truncate regular writable file when opened.
o_append = 0o00002000 // append data to the file when writing.
o_nonblock = 0o00004000 // prevents blocking when opening files
o_sync = 0o04010000 // open for synchronous I/O.
)
21 changes: 15 additions & 6 deletions vlib/os/os_android.c.v
Original file line number Diff line number Diff line change
@@ -1,29 +1,38 @@
module os

struct C.ANativeActivity {
assetManager &C.AAsetManager
struct C.AAset {
}

struct C.AAssetManager {
}

struct C.AAset {}
struct C.ANativeActivity {
assetManager voidptr
}

fn C.AAssetManager_open(&C.AAsetManager, charptr, int) &C.AAset

fn C.AAsset_getLength(&C.AAset) int

fn C.AAsset_read(&C.AAset, voidptr, int) int

fn C.AAsset_close(&C.AAsset)

pub fn read_apk_asset(file string) ?[]byte {
act := &C.ANativeActivity(C.sapp_android_get_native_activity())
if isnil(act) {
return error('Could not get reference to Android activity')
}
asset := C.AAssetManager_open(act.assetManager, file.str, C.AASSET_MODE_STREAMING)
asset := C.AAssetManager_open(&C.AAsetManager(act.assetManager), file.str, C.AASSET_MODE_STREAMING)
if isnil(asset) {
return error('File `$file` not found')
}
len := C.AAsset_getLength(asset)
buf := []byte{ len: len }
buf := []byte{len: len}
for {
if C.AAsset_read(asset, buf.data, len) > 0 { break }
if C.AAsset_read(asset, buf.data, len) > 0 {
break
}
}
C.AAsset_close(asset)
return buf
Expand Down

0 comments on commit 1ee5764

Please sign in to comment.