v/vlib/os
2025-04-23 07:52:07 +03:00
..
asset examples,os: add an os.asset module, use it to simplify code in examples/, by removing $if android { checks (#22281) 2024-09-22 16:04:05 +03:00
bare ci: re-enable testing of ./v -freestanding run vlib/os/bare/bare_example_linux.v on ubuntu 2021-04-22 12:50:56 +03:00
cmdline builtin: remove methods that can be autogenerated (#11109) 2021-08-09 15:42:31 +03:00
filelock os.filelock: compile without warnings with gcc on windows 2025-04-23 07:52:07 +03:00
font gg: fix ./v -gc none -autofree run examples/tetris/ (avoid return s1 + s2 + s3, clone the arrays, passed to the fontstash wrapper) 2025-02-07 14:29:43 +02:00
notify fmt: remove the prefixed module name of const names, that are in the same module (related #22183) (#22185) 2024-09-10 11:25:56 +03:00
args.v all: update copyright year (#20334) 2024-01-01 23:29:54 +02:00
const.v os: add a posix_set_permission_bit function (#7754) 2021-01-04 19:57:17 +02:00
const_nix.c.v all: unwrap const() blocks 2023-11-25 10:02:51 +03:00
const_windows.c.v all: unwrap const() blocks 2023-11-25 10:02:51 +03:00
debugger_darwin.c.v os: fix debugger_present() for non Windows OSes (#21573) 2024-05-26 00:46:43 +03:00
debugger_default.c.v all: update attributes to use new syntax 2023-11-15 16:16:01 +11:00
debugger_freebsd.c.v os: fix debugger_present() for non Windows OSes (#21573) 2024-05-26 00:46:43 +03:00
debugger_linux.c.v os: fix debugger_present() for non Windows OSes (#21573) 2024-05-26 00:46:43 +03:00
debugger_windows.c.v all: update attributes to use new syntax 2023-11-15 16:16:01 +11:00
dir_expansions_test.v all: change single blank comment to blank line (#22016) 2024-08-09 14:55:58 +03:00
environment.c.v os: use _wputenv instead of _putenv to stay in sync with _wgetenv (fix changing env variables with non ASCII content on windows) (#22920) 2024-11-21 01:33:02 +02:00
environment.js.v vlib: update doc comments (#19231) 2023-08-30 08:50:00 +03:00
environment_test.v os: use _wputenv instead of _putenv to stay in sync with _wgetenv (fix changing env variables with non ASCII content on windows) (#22920) 2024-11-21 01:33:02 +02:00
fd.c.v all: replace fn name '@xxx' with 'xxx' (#22506) 2024-10-12 22:17:02 +03:00
file.c.v checker, cgen: fix non-voidptr to voidptr on -cstrict + notice about such usage (fix #24139) (#24143) 2025-04-06 08:27:57 +03:00
file.js.v fmt: fix alignment of struct init fields (#22025) 2024-08-11 09:11:24 +03:00
file_buffering.c.v os: add File.set_buffer and related helpers + tests (#20661) 2024-01-26 20:44:23 +02:00
file_buffering_test.v all: change single blank comment to blank line (#22016) 2024-08-09 14:55:58 +03:00
file_le_be.c.v os: fix swap_bytes_u64 (#24033) 2025-03-25 15:34:57 +02:00
file_le_be_test.v os: fix swap_bytes_u64 (#24033) 2025-03-25 15:34:57 +02:00
file_test.v builtin: implement a s.hex() method, allowing shortening s.bytes().hex() chains, and reducing the intermediate allocations; add tests for it (#22540) 2024-10-16 14:18:10 +03:00
filepath.v Revert "os: deprecate os.getwd in favor of os.get_current_dir (part 1) (#22966)" 2024-11-25 15:10:15 +02:00
filepath_test.v Revert "os: deprecate os.getwd in favor of os.get_current_dir (part 1) (#22966)" 2024-11-25 15:10:15 +02:00
filepath_windows.v os: correct description of windows_volume function (#14726) 2022-06-09 10:56:58 +03:00
find_abs_path_of_executable_test.v Revert "os: deprecate os.getwd in favor of os.get_current_dir (part 1) (#22966)" 2024-11-25 15:10:15 +02:00
glob_test.v all: change optional to result of io (#16075) 2022-10-16 09:28:57 +03:00
inode.c.v fmt: fix alignment of struct init fields (#22025) 2024-08-11 09:11:24 +03:00
inode_test.v ci: improve test robustness on windows (#21116) 2024-03-28 07:29:17 +02:00
join_path_test.v os: simplify and unify os.join_path and os.join_path_single, and add more tests (#21494) 2024-05-13 17:33:10 +03:00
open_and_read_from_file_test.js.v tools: cleanup entries from the hardcoded skip_files list in common.v (used by v test, v test-self etc); use the new // vtest build: syntax to mark the tests instead (#23918) 2025-03-13 19:51:51 +02:00
open_uri_default.c.v vlib: update doc comments (#19231) 2023-08-30 08:50:00 +03:00
open_uri_windows.c.v os: use 1 instead of C.SW_SHOWNORMAL to workaround a cross compilation issue from linux to windows 2024-05-21 19:47:04 +03:00
os.c.v os,v.transformer: fix warnings for ./v -os cross -o vc/v.c cmd/v && clang-18 -o v_from_vc vc/v.c -lpthread 2025-03-06 21:05:01 +02:00
os.js.v fmt: fix alignment of struct init fields (#22025) 2024-08-11 09:11:24 +03:00
os.v v.pref: allow for -os wasm32_emscripten and filtering _d_wasm32_emscripten.c.v and _notd_wasm32_emscripten.c.v files. (#23797) 2025-02-24 11:23:37 +02:00
os_android_outside_termux.c.v fmt: fix alignment of enumeration types (#21999) 2024-08-07 15:46:50 +03:00
os_darwin.c.v all: update copyright year (#20334) 2024-01-01 23:29:54 +02:00
os_js.js.v Revert "os: deprecate os.getwd in favor of os.get_current_dir (part 1) (#22966)" 2024-11-25 15:10:15 +02:00
os_linux.c.v all: update copyright year (#20334) 2024-01-01 23:29:54 +02:00
os_nix.c.v os: add disk_usage/1 (#23634) 2025-02-02 19:32:21 +02:00
os_stat_default.c.v fmt: fix formating a file in an oscillating manner (fix #22223, fix #22026) (#22232) 2024-09-17 09:47:38 +03:00
os_stat_test.v tests: skip an assertion in os_stat_test.v on OpenBSD (fix #22123) (#22124) 2024-08-28 11:23:08 +03:00
os_stat_windows.c.v fmt: fix formating a file in an oscillating manner (fix #22223, fix #22026) (#22232) 2024-09-17 09:47:38 +03:00
os_structs_dirent_default.c.v all: make all struct C.XYZ -> pub struct C.XYZ (#19651) 2023-10-25 15:01:50 +03:00
os_structs_sigaction_default.c.v all: make all struct C.XYZ -> pub struct C.XYZ (#19651) 2023-10-25 15:01:50 +03:00
os_structs_stat_default.c.v os: add os.stat() and helpers (#20739) 2024-02-07 07:12:03 +02:00
os_structs_stat_linux.c.v all: make all struct C.XYZ -> pub struct C.XYZ (#19651) 2023-10-25 15:01:50 +03:00
os_structs_stat_windows.c.v ci: fix failing vlib/v/tests/option_test.c.v 2024-05-19 10:11:27 +03:00
os_structs_utsname_default.c.v all: make all struct C.XYZ -> pub struct C.XYZ (#19651) 2023-10-25 15:01:50 +03:00
os_test.c.v ci: add a s390x job (using QEMU), running the endianness related tests in builtin, os, and encoding.binary (#24153) 2025-04-07 23:35:33 +03:00
os_windows.c.v os: add disk_usage/1 (#23634) 2025-02-02 19:32:21 +02:00
password_nix.c.v os,term.termios: add termios.set_state/2, state.disable_echo/0, use them in os.input_password, to fix v -os wasm32_emscripten examples/2048/ 2023-07-31 10:28:45 +03:00
password_windows.c.v clipboard: fix v -cstrict -cc gcc vlib/clipboard/clipboard_test.v 2023-10-15 21:21:29 +03:00
process.c.v os: implement Process.is_pending() on windows (fix #23990) (#23993) 2025-03-21 11:03:03 +02:00
process.js.v vfmt: change all '$expr' to '${expr}' (#16428) 2022-11-15 16:53:13 +03:00
process.v fmt: fix and simplify align of struct fields (#21995) 2024-08-05 20:23:39 +03:00
process_nix.c.v os: implement Process.is_pending() on windows (fix #23990) (#23993) 2025-03-21 11:03:03 +02:00
process_test.v os,tools: make easier analyzing process_test.v failures on the CI 2025-03-26 14:00:47 +02:00
process_windows.c.v checker: do not allow auto (de)reference in PrefixExpr *; pref: disable parallel checker on arm linux for now 2025-03-24 15:39:31 +03:00
README.md os: format readme, fix markdown inside html (#21286) 2024-04-15 14:56:44 +03:00
signal.c.v v: use -check-unused-fn-args to cleanup the compiler code itself 2024-11-18 12:10:03 +02:00
signal.js.v os: return the long path for os.temp_dir() on windows, even for folders like c:\someth~1 (#17623) 2023-03-14 00:51:52 +02:00
signal.v os: document the various enum values in os.Signal (#22770) 2024-11-05 20:50:09 +02:00
signal_darwin.c.v all: update attributes to use new syntax 2023-11-15 16:16:01 +11:00
signal_default.c.v os: fix bootstrapping for OpenBSD 2023-11-16 13:43:55 +02:00
signal_linux.c.v os: fix bootstrapping for OpenBSD 2023-11-16 13:43:55 +02:00
signal_test.v builtin: simplify MessageError.msg() (#21524) 2024-05-18 22:36:24 +03:00
signal_windows.c.v v: use -check-unused-fn-args to cleanup the compiler code itself 2024-11-18 12:10:03 +02:00
sleeping.c.v os: improve robustness of create_folder_when_it_does_not_exist/1 (fix CI false positives for vab-compiles-v-examples) (#22548) 2024-10-17 15:51:04 +03:00
sleeping.js.v os: improve robustness of create_folder_when_it_does_not_exist/1 (fix CI false positives for vab-compiles-v-examples) (#22548) 2024-10-17 15:51:04 +03:00
xdg_test.v os: implement os.data_dir(), os.state_dir(), os.local_bin_dir() + tests (#22426) 2024-10-07 07:23:50 +03:00

Description

os provides common OS/platform independent functions for accessing command line arguments, reading/writing files, listing folders, handling processes etc.


A few os module functions can lead to the TOCTOU vulnerability if used incorrectly. TOCTOU (Time-of-Check-to-Time-of-Use problem) can occur when a file, folder or similar is checked for certain specifications (e.g. read, write permissions) and a change is made afterwards. In the time between the initial check and the edit, an attacker can then cause damage. The following example shows an attack strategy on the left and an improved variant on the right so that TOCTOU is no longer possible.

Example
Hint: os.create() opens a file in write-only mode

Possibility for TOCTOU attack TOCTOU not possible
if os.is_writable("file") {
    // time to make a quick attack
    // (e.g. symlink /etc/passwd to `file`)

    mut f := os.create('path/to/file')!
    // do something with file
    f.close()
}
mut f := os.create('path/to/file') or {
    println("file not writable")
}

// file is locked
// do something with file

f.close()

Proven affected functions
The following functions should be used with care and only when used correctly.

  • os.is_readable()
  • os.is_writable()
  • os.is_executable()
  • os.is_link()