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

os: document functions

This commit is contained in:
Don Alfons Nisnoni 2019-10-27 01:21:07 +08:00 committed by Alexander Medvednikov
parent 2d05c906d5
commit 678ce54e70

View File

@ -80,15 +80,12 @@ pub fn (f File) read_bytes(size int) []byte {
pub fn (f File) read_bytes_at(size, pos int) []byte {
mut data := malloc(size)
mut arr := [`0`].repeat(size)
C.fseek(f.cfile, pos, C.SEEK_SET)
C.fread(data, 1, size, f.cfile)
C.fseek(f.cfile, 0, C.SEEK_SET)
for e := 0; e < size; e++ {
arr[e] = data[e]
}
return arr
}
@ -591,7 +588,7 @@ pub fn get_lines_joined() string {
mut inputstr := ''
for {
line = get_line()
if(line.len <= 0) {
if line.len <= 0 {
break
}
line = line.trim_space()
@ -600,6 +597,7 @@ pub fn get_lines_joined() string {
return inputstr
}
// user_os returns current user operating system name.
pub fn user_os() string {
$if linux {
return 'linux'
@ -658,6 +656,7 @@ pub fn write_file(path, text string) {
f.close()
}
// clear will clear current terminal screen.
pub fn clear() {
$if !windows {
C.printf('\x1b[2J')
@ -682,6 +681,7 @@ fn on_segfault(f voidptr) {
fn C.getpid() int
fn C.proc_pidpath (int, byteptr, int) int
// executable return the path name of the executable that started the current process.
pub fn executable() string {
$if linux {
mut result := malloc(MAX_PATH)
@ -740,6 +740,7 @@ pub fn executable() string {
return os.args[0]
}
// is_dir returns a boolean indicating whether the given path is a directory.
pub fn is_dir(path string) bool {
$if windows {
return dir_exists(path)
@ -758,6 +759,7 @@ pub fn is_dir(path string) bool {
}
}
// chdir changes the current working directory to the new directory path.
pub fn chdir(path string) {
$if windows {
C._wchdir(path.to_wide())
@ -767,6 +769,7 @@ pub fn chdir(path string) {
}
}
// getwd returns the absolute path name of the current directory.
pub fn getwd() string {
$if windows {
max := 512 // MAX_PATH * sizeof(wchar_t)