diff --git a/vlib/os/file_test.v b/vlib/os/file_test.v index a4fe309d07..764360019d 100644 --- a/vlib/os/file_test.v +++ b/vlib/os/file_test.v @@ -477,3 +477,18 @@ fn test_open_file_crlf_binary_mode() { assert fcont_wb == teststr } + +fn test_path_devnull() { + dump(os.path_devnull) + content := os.read_file(os.path_devnull)! + // dump(content) + // dump(content.len) + + os.write_file(os.path_devnull, 'something')! + + content_after := os.read_file(os.path_devnull)! + // dump(content_after) + // dump(content_after.len) + assert content.len == 0 + assert content_after.len == 0 +} diff --git a/vlib/os/os.js.v b/vlib/os/os.js.v index ad177c161d..f9d9c735c6 100644 --- a/vlib/os/os.js.v +++ b/vlib/os/os.js.v @@ -8,6 +8,8 @@ $if js_node { pub const path_delimiter = get_path_delimiter() pub const path_separator = get_path_separator() +pub const path_devnull = '/dev/null' // TODO + pub const args = []string{} const executable_suffixes = [''] diff --git a/vlib/os/os_nix.c.v b/vlib/os/os_nix.c.v index 8906c2ee9c..8fdc649215 100644 --- a/vlib/os/os_nix.c.v +++ b/vlib/os/os_nix.c.v @@ -9,9 +9,18 @@ import strings #include #include +// path_separator is the platform specific separator string, used between the folders +// and filenames in a path. It is '/' on POSIX, and '\\' on Windows. pub const path_separator = '/' + +// path_delimiter is the platform specific delimiter string, used between the paths +// in environment variables like PATH. It is ':' on POSIX, and ';' on Windows. pub const path_delimiter = ':' +// path_devnull is a platform-specific file path of the null device. +// It is '/dev/null' on POSIX, and r'\\.\nul' on Windows. +pub const path_devnull = '/dev/null' + const executable_suffixes = [''] const stdin_value = 0 diff --git a/vlib/os/os_windows.c.v b/vlib/os/os_windows.c.v index 8356771a38..3b7f39d3d3 100644 --- a/vlib/os/os_windows.c.v +++ b/vlib/os/os_windows.c.v @@ -6,6 +6,18 @@ import strings #include #include +// path_separator is the platform specific separator string, used between the folders +// and filenames in a path. It is '/' on POSIX, and '\\' on Windows. +pub const path_separator = '\\' + +// path_delimiter is the platform specific delimiter string, used between the paths +// in environment variables like PATH. It is ':' on POSIX, and ';' on Windows. +pub const path_delimiter = ';' + +// path_devnull is a platform-specific file path of the null device. +// It is '/dev/null' on POSIX, and r'\\.\nul' on Windows. +pub const path_devnull = r'\\.\nul' + // See https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createsymboliclinkw fn C.CreateSymbolicLinkW(&u16, &u16, u32) int @@ -16,9 +28,6 @@ fn C._getpid() int const executable_suffixes = ['.exe', '.bat', '.cmd', ''] -pub const path_separator = '\\' -pub const path_delimiter = ';' - // Ref - https://docs.microsoft.com/en-us/windows/desktop/winprog/windows-data-types // A handle to an object. pub type HANDLE = voidptr