os #

Constants #

const (
	args          = []string{}
	max_path_len  = 4096
	wd_at_startup = getwd()
const (
	path_separator = '/'
	path_delimiter = ':'
const (
	s_ifmt  = 0xF000
	s_ifdir = 0x4000
	s_iflnk = 0xa000
	s_isuid = 0o4000
	s_isgid = 0o2000
	s_isvtx = 0o1000
	s_irusr = 0o0400
	s_iwusr = 0o0200
	s_ixusr = 0o0100
	s_irgrp = 0o0040
	s_iwgrp = 0o0020
	s_ixgrp = 0o0010
	s_iroth = 0o0004
	s_iwoth = 0o0002
	s_ixoth = 0o0001

(Must be realized in Syscall) (Must be specified) ref: http://www.ccfit.nsu.ru/~deviv/courses/unix/unix/ng7c229.html

fn args_after #

fn args_after(cut_word string) []string

args_after returns all os.args, located after a specified cut_word. When cut_word is NOT found, os.args is returned unmodified.

fn args_before #

fn args_before(cut_word string) []string

args_after returns all os.args, located before a specified cut_word. When cut_word is NOT found, os.args is returned unmodified.

fn base #

fn base(path string) string

base returns the last element of path. Trailing path separators are removed before extracting the last element. If the path is empty, base returns ".". If the path consists entirely of separators, base returns a single separator.

fn cache_dir #

fn cache_dir() string

cache_dir returns the path to a writable user specific folder, suitable for writing non-essential data.

fn chdir #

fn chdir(path string)

chdir changes the current working directory to the new directory in path.

fn chmod #

fn chmod(path string, mode int)

chmod change file access attributes of path to mode. Octals like 0o600 can be used.

fn cp #

fn cp(src string, dst string) ?

cp copies files or folders from src to dst.

fn cp_all #

fn cp_all(src string, dst string, overwrite bool) ?

cp_all will recursively copy src to dst, optionally overwriting files or dirs in dst.

fn cp_r #

fn cp_r(osource_path string, odest_path string, overwrite bool) ?

fn create #

fn create(path string) ?File

create creates or opens a file at a specified location and returns a write-only File object.

fn debugger_present #

fn debugger_present() bool

fn dir #

fn dir(path string) string

dir returns all but the last element of path, typically the path's directory. After dropping the final element, trailing slashes are removed. If the path is empty, dir returns ".". If the path consists entirely of separators, dir returns a single separator. The returned path does not end in a separator unless it is the root directory.

fn dir_exists #

fn dir_exists(path string) bool

fn environ #

fn environ() map[string]string

See: https://linux.die.net/man/5/environ for unix platforms. See: https://docs.microsoft.com/bg-bg/windows/win32/api/processenv/nf-processenv-getenvironmentstrings os.environ returns a map of all the current environment variables

fn exec #

fn exec(cmd string) ?Result

exec starts the specified command, waits for it to complete, and returns its output.

fn executable #

fn executable() string

executable returns the path name of the executable that started the current process.

fn execve #

fn execve(cmdpath string, args []string, envs []string) ?

execve - loads and executes a new child process, in place of the current process. The child process executable is located in cmdpath. The arguments, that will be passed to it are in args. You can pass environment variables to through envs. NB: this function will NOT return when successfull, since the child process will take control over execution.

fn execvp #

fn execvp(cmdpath string, args []string) ?

execvp - loads and executes a new child process, in place of the current process. The child process executable is located in cmdpath. The arguments, that will be passed to it are in args. NB: this function will NOT return when successfull, since the child process will take control over execution.

fn exists #

fn exists(path string) bool

exists returns true if path (file or directory) exists.

fn exists_in_system_path #

fn exists_in_system_path(prog string) bool

exists_in_system_path returns true if prog exists in the system's PATH

fn fd_close #

fn fd_close(fd int) int

file descriptor based operations:

fn fd_read #

fn fd_read(fd int, maxbytes int) (string, int)

fn fd_slurp #

fn fd_slurp(fd int) []string

fn fd_write #

fn fd_write(fd int, s string)

fn file_exists #

fn file_exists(_path string) bool

fn file_ext #

fn file_ext(path string) string

file_ext will return the part after the last occurence of . in path. The . is included.

fn file_last_mod_unix #

fn file_last_mod_unix(path string) int

file_last_mod_unix returns the "last modified" time stamp of file in path.

fn file_name #

fn file_name(path string) string

file_name will return all characters found after the last occurence of path_separator. file extension is included.

fn file_size #

fn file_size(path string) int

***************************** OS ops ************************ file_size returns the size of the file located in path.

fn fileno #

fn fileno(cfile voidptr) int

fileno returns the file descriptor of an opened C file.

fn find_abs_path_of_executable #

fn find_abs_path_of_executable(exepath string) ?string

find_exe_path walks the environment PATH, just like most shell do, it returns the absolute path of the executable if found

fn flush #

fn flush()

flush will flush the stdout buffer.

fn flush_stdout #

fn flush_stdout()

fn fork #

fn fork() int

fork will fork the current system process and return the pid of the fork.

fn get_error_msg #

fn get_error_msg(code int) string

get_error_msg return error code representation in string.

fn get_line #

fn get_line() string

get_line returns a one-line string from stdin

fn get_lines #

fn get_lines() []string

get_lines returns an array of strings read from from stdin. reading is stopped when an empty line is read.

fn get_lines_joined #

fn get_lines_joined() string

get_lines_joined returns a string of the values read from from stdin. reading is stopped when an empty line is read.

fn get_raw_line #

fn get_raw_line() string

get_raw_line returns a one-line string from stdin along with '\n' if there is any.

fn get_raw_stdin #

fn get_raw_stdin() []byte

get_raw_stdin will get the raw input from stdin.

fn getenv #

fn getenv(key string) string

fn getpid #

fn getpid() int

fn getwd #

fn getwd() string

getwd returns the absolute path of the current directory.

fn home_dir #

fn home_dir() string

home_dir returns path to the user's home directory.

fn inode #

fn inode(path string) FileMode

inode returns the mode of the file/inode containing inode type and permission information it supports windows for regular files but it doesn't matter if you use owner, group or others when checking permissions on windows

fn input #

fn input(prompt string) string

input returns a one-line string from stdin, after printing a prompt.

fn is_abs_path #

fn is_abs_path(path string) bool

is_abs_path returns true if path is absolute.

fn is_dir #

fn is_dir(path string) bool

is_dir returns a bool indicating whether the given path is a directory.

fn is_dir_empty #

fn is_dir_empty(path string) bool

is_dir_empty will return a bool whether or not path is empty.

fn is_executable #

fn is_executable(path string) bool

is_executable returns true if path is executable.

fn is_file #

fn is_file(path string) bool

is_file returns a bool indicating whether the given path is a file.

fn is_readable #

fn is_readable(path string) bool

is_readable returns true if path is readable.

fn is_writable #

fn is_writable(path string) bool

is_writable returns true if path is writable.

fn is_writable_folder #

fn is_writable_folder(folder string) ?bool

fn join_path #

fn join_path(base string, dirs ...string) string

join_path returns a path as string from input string parameter(s).

fn log #

fn log(s string)

log will print "os.log: "+s ...

fn ls #

fn ls(path string) ?[]string

fn mkdir #

fn mkdir(path string) ?bool

mkdir creates a new directory with the specified path.

fn mkdir_all #

fn mkdir_all(path string) ?

mkdir_all will create a valid full path of all directories given in path.

fn mv #

fn mv(src string, dst string) ?

mv moves files or folders from src to dst.

fn mv_by_cp #

fn mv_by_cp(source string, target string) ?

mv_by_cp first copies the source file, and if it is copied successfully, deletes the source file. may be used when you are not sure that the source and target are on the same mount/partition.

fn new_process #

fn new_process(filename string) &Process

new_process - create a new process descriptor NB: new does NOT start the new process. That is done because you may want to customize it first, by calling different set_ methods on it. In order to start it, call p.run() or p.wait()

fn on_segfault #

fn on_segfault(f voidptr)

fn open #

fn open(path string) ?File

open tries to open a file for reading and returns back a read-only File object.

fn open_append #

fn open_append(path string) ?File

open_append opens path file for appending.

fn open_file #

fn open_file(path string, mode string, options ...int) ?File

open_file can be used to open or create a file with custom flags and permissions and returns a File object.

fn open_stdin #

fn open_stdin() File

open_stdin - return an os.File for stdin, so that you can use .get_line on it too.

fn posix_get_error_msg #

fn posix_get_error_msg(code int) string

posix_get_error_msg return error code representation in string.

fn posix_set_permission_bit #

fn posix_set_permission_bit(path_s string, mode u32, enable bool)

Turns the given bit on or off, depending on the enable parameter

fn read_bytes #

fn read_bytes(path string) ?[]byte

read_bytes returns all bytes read from file in path.

fn read_file #

fn read_file(path string) ?string

read_file reads the file in path and returns the contents.

fn read_file_array #

fn read_file_array<T>(path string) []T

read_file_array reads an array of T values from file path.

fn read_lines #

fn read_lines(path string) ?[]string

read_lines reads the file in path into an array of lines.

fn real_path #

fn real_path(fpath string) string

real_path returns the full absolute path for fpath, with all relative ../../, symlinks and so on resolved. See http://pubs.opengroup.org/onlinepubs/9699919799/functions/realpath.html Also https://insanecoding.blogspot.com/2007/11/pathmax-simply-isnt.html and https://insanecoding.blogspot.com/2007/11/implementing-realpath-in-c.html NB: this particular rabbit hole is deep ...

fn resource_abs_path #

fn resource_abs_path(path string) string

resource_abs_path returns an absolute path, for the given path. (the path is expected to be relative to the executable program) See https://discordapp.com/channels/592103645835821068/592294828432424960/630806741373943808 It gives a convenient way to access program resources like images, fonts, sounds and so on, no matter how the program was started, and what is the current working directory.

fn rm #

fn rm(path string) ?

rm removes file in path.

fn rmdir #

fn rmdir(path string) ?

rmdir removes a specified directory.

fn rmdir_all #

fn rmdir_all(path string) ?

rmdir_all recursively removes the specified directory.

fn rmdir_recursive #

fn rmdir_recursive(path string)

fn setenv #

fn setenv(name string, value string, overwrite bool) int

os.setenv sets the value of an environment variable with name to value.

fn sigint_to_signal_name #

fn sigint_to_signal_name(si int) string

sigint_to_signal_name will translate si signal integer code to it's string code representation.

fn signal #

fn signal(signum int, handler voidptr)

signal will assign handler callback to be called when signum signal is recieved.

fn system #

fn system(cmd string) int

system works like exec, but only returns a return code.

fn temp_dir #

fn temp_dir() string

temp_dir returns the path to a folder, that is suitable for storing temporary files.

fn uname #

fn uname() Uname

fn unsetenv #

fn unsetenv(name string) int

os.unsetenv clears an environment variable with name.

fn user_os #

fn user_os() string

user_os returns current user operating system name.

fn vfopen #

fn vfopen(path string, mode string) ?&C.FILE

vfopen returns an opened C file, given its path and open mode. NB: os.vfopen is useful for compatibility with C libraries, that expect FILE *. If you write pure V code, os.create or os.open are more convenient.

fn vmodules_dir #

fn vmodules_dir() string

vmodules_dir returns the path to a folder, where v stores its global modules.

fn vmodules_paths #

fn vmodules_paths() []string

vmodules_paths returns a list of paths, where v looks up for modules. You can customize it through setting the environment variable VMODULES

fn wait #

fn wait() int

wait blocks the calling process until one of its child processes exits or a signal is received. After child process terminates, parent continues its execution after wait system call instruction.

fn walk #

fn walk(path string, f fn (string))

walk recursively traverses the given directory path. When a file is encountred it will call the callback function with current file as argument.

fn walk_ext #

fn walk_ext(path string, ext string) []string

walk_ext returns a recursive list of all files in path ending with ext.

fn write_file #

fn write_file(path string, text string) ?

write_file writes text data to a file in path.

fn write_file_array #

fn write_file_array(path string, buffer array) ?

write_file_array writes the data in buffer to a file in path.

enum ProcessState #

enum ProcessState {

ProcessState.not_started - the process has not yet started ProcessState.running - the process is currently running ProcessState.stopped - the process was running, but was stopped temporarily ProcessState.exited - the process has finished/exited ProcessState.aborted - the process was terminated by a signal

struct Command #

struct Command {
	f voidptr
pub mut:
	eof bool
	path            string
	redirect_stdout bool

fn (Command) start #

fn (mut c Command) start() ?

pub fn command(cmd Command) Command { }

fn (Command) read_line #

fn (mut c Command) read_line() string

fn (Command) close #

fn (c &Command) close() ?

struct File #

struct File {
	cfile voidptr
	fd int
pub mut:
	is_opened bool

fn (File) close #

fn (mut f File) close()

fn (File) flush #

fn (mut f File) flush()

**************************** Utility ops *********************** flush writes any unwritten data in stream's buffer

fn (File) get_line #

fn (mut f File) get_line() ?string

File.get_line - get a single line from the file. NB: the ending newline is included.

fn (File) is_opened #

fn (f File) is_opened() bool

fn (File) read #

fn (f &File) read(mut buf []byte) ?int

read implements the Reader interface

fn (File) read_at #

fn (f &File) read_at(pos int, mut buf []byte) ?int

read_at reads buf.len bytes from pos in the file

fn (File) read_bytes #

fn (f &File) read_bytes(size int) []byte

**************************** Read ops *************************** read_bytes reads bytes from the beginning of the file

fn (File) read_bytes_at #

fn (f &File) read_bytes_at(size int, pos int) []byte

read_bytes_at reads bytes at the given position in the file

fn (File) read_bytes_into #

fn (f &File) read_bytes_into(pos int, mut buf []byte) ?int

read_bytes_into fills buf with bytes at the given position in the file. buf must have length greater than zero. Returns number of bytes read or an error.

fn (File) write #

fn (mut f File) write(buf []byte) ?int

**************************** Write ops *************************** write implements the Writer interface

fn (File) write_bytes #

fn (mut f File) write_bytes(data voidptr, size int) int

fn (File) write_bytes_at #

fn (mut f File) write_bytes_at(data voidptr, size int, pos int) int

fn (File) write_str #

fn (mut f File) write_str(s string) ?

fn (File) write_string #

fn (mut f File) write_string(s string) ?int

fn (File) write_to #

fn (mut f File) write_to(pos int, buf []byte) ?int

write_to implements the RandomWriter interface

fn (File) writeln #

fn (mut f File) writeln(s string) ?int

struct Process #

struct Process {
	filename string
pub mut:
	pid  int
	code int = -1
	status ProcessState = .not_started
	err           string
	args          []string
	env_is_custom bool
	env           []string
	use_stdio_ctl bool
	stdio_fd      [3]int

fn (Process) set_args #

fn (mut p Process) set_args(pargs []string) &Process

set_args - set the arguments for the new process

fn (Process) set_environment #

fn (mut p Process) set_environment(envs map[string]string) &Process

set_environment - set a custom environment variable mapping for the new process

fn (Process) run #

fn (mut p Process) run() &Process

run - starts the new process

fn (Process) signal_kill #

fn (mut p Process) signal_kill() &Process

signal_kill - kills the process, after that it is no longer running

fn (Process) signal_stop #

fn (mut p Process) signal_stop() &Process

signal_stop - stops the process, you can resume it with p.signal_continue()

fn (Process) signal_continue #

fn (mut p Process) signal_continue() &Process

signal_continue - tell a stopped process to continue/resume its work

fn (Process) wait #

fn (mut p Process) wait() &Process

wait - wait for a process to finish. NB: You have to call p.wait(), otherwise a finished process would get to a zombie state, and its resources will not get released fully, until its parent process exits. NB: This call will block the calling process until the child process is finished.

fn (Process) is_alive #

fn (mut p Process) is_alive() bool

is_alive - query whether the process p.pid is still alive

fn (Process) set_redirect_stdio #

fn (mut p Process) set_redirect_stdio() &Process

fn (Process) stdin_write #

fn (mut p Process) stdin_write(s string)

fn (Process) stdout_slurp #

fn (mut p Process) stdout_slurp() string

fn (Process) stderr_slurp #

fn (mut p Process) stderr_slurp() string

fn (Process) stdout_read #

fn (mut p Process) stdout_read() string

fn (Process) stderr_read #

fn (mut p Process) stderr_read() string

struct Result #

struct Result {
	exit_code int
	output    string

struct Uname #

struct Uname {
pub mut:
	sysname  string
	nodename string
	release  string
	version  string
	machine  string