Higher-level interfaces to libc::* functions and operating system services.
In general these take and return rust types, use rust idioms (enums, closures, vectors) rather than C idioms, and do more extensive safety checks.
This module is not meant to only contain 1:1 mappings to libc entries; any os-interface code that is reasonably useful and broadly applicable can go here. Including utility routines that merely build on other os code.
We assume the general case is that users do not care, and do not want to be made to care, which operating system they are on. While they may want to special case various special cases -- and so we will not hide the facts of which OS the user is on -- they should be given the opportunity to write OS-ignorant code by default.
tmpbuf_sz
LPCWSTR
OverriddenArgs
arch
args
as_c_charp
change_dir
copy_file
- Copies a file from one location to anotherdll_filename
dup2
env
family
fdopen
fill_charp_buf
fsync_fd
getcwd
getenv
homedir
- Returns the path to the user's home directory, if known.last_os_error
- Get a string representing the platform-dependent last errorlist_dir
- Lists the contents of a directorylist_dir_path
- Lists the contents of a directoryload_argc_and_argv
make_absolute
- Convert a relative path to an absolute pathmake_dir
- Creates a directory at the specified pathoverridden_arg_key
path_exists
- Indicates whether a path existspath_is_dir
- Indicates whether a path represents a directorypipe
real_args
remove_dir
- Removes a directory at the specified pathremove_file
- Deletes an existing fileself_exe_path
set_args
set_exit_status
- Sets the process exit codesetenv
tmpdir
- Returns the path to a temporary directory.waitpid
walk_dir
- Recursively walk a directory structureos::consts
os::global_env
- Internal module for serializing access to getenv/setenvos::rustrt
tmpbuf_sz
uint
LPCWSTR
type LPCWSTR = *u16
OverriddenArgs
struct OverriddenArgs {
val: ~[~str],
}
arch
fn arch() -> ~str
args
fn args() -> ~[~str]
as_c_charp
fn as_c_charp<T>(s: &str, f: &fn(*c_char) -> T) -> T
change_dir
fn change_dir(p: &Path) -> bool
copy_file
fn copy_file(from: &Path, to: &Path) -> bool
Copies a file from one location to another
dll_filename
fn dll_filename(base: &str) -> ~str
dup2
fn dup2(src: c_int, dst: c_int) -> c_int
env
fn env() -> ~[(~str, ~str)]
family
fn family() -> ~str
fdopen
fn fdopen(fd: c_int) -> *FILE
fill_charp_buf
fn fill_charp_buf(f: &fn(*mut c_char, size_t) -> bool) -> Option<~str>
fsync_fd
fn fsync_fd(fd: c_int, level: io::fsync::Level) -> c_int
getcwd
fn getcwd() -> Path
getenv
fn getenv(n: &str) -> Option<~str>
homedir
fn homedir() -> Option<Path>
Returns the path to the user's home directory, if known.
On Unix, returns the value of the 'HOME' environment variable if it is set and not equal to the empty string.
On Windows, returns the value of the 'HOME' environment variable if it is set and not equal to the empty string. Otherwise, returns the value of the 'USERPROFILE' environment variable if it is set and not equal to the empty string.
Otherwise, homedir returns option::none.
last_os_error
fn last_os_error() -> ~str
Get a string representing the platform-dependent last error
list_dir
fn list_dir(p: &Path) -> ~[~str]
Lists the contents of a directory
list_dir_path
fn list_dir_path(p: &Path) -> ~[~Path]
Lists the contents of a directory
This version prepends each entry with the directory.
load_argc_and_argv
fn load_argc_and_argv(argc: c_int, argv: **c_char) -> ~[~str]
make_absolute
fn make_absolute(p: &Path) -> Path
Convert a relative path to an absolute path
If the given path is relative, return it prepended with the current working directory. If the given path is already an absolute path, return it as is.
make_dir
fn make_dir(p: &Path, mode: c_int) -> bool
Creates a directory at the specified path
overridden_arg_key
fn overridden_arg_key(_v: @OverriddenArgs)
path_exists
fn path_exists(p: &Path) -> bool
Indicates whether a path exists
path_is_dir
fn path_is_dir(p: &Path) -> bool
Indicates whether a path represents a directory
pipe
fn pipe() -> {in: c_int, out: c_int,}
real_args
fn real_args() -> ~[~str]
remove_dir
fn remove_dir(p: &Path) -> bool
Removes a directory at the specified path
remove_file
fn remove_file(p: &Path) -> bool
Deletes an existing file
self_exe_path
fn self_exe_path() -> Option<Path>
set_args
fn set_args(new_args: ~[~str])
set_exit_status
fn set_exit_status(code: int)
Sets the process exit code
Sets the exit code returned by the process if all supervised tasks terminate successfully (without failing). If the current root task fails and is supervised by the scheduler then any user-specified exit status is ignored and the process exits with the default failure status
setenv
fn setenv(n: &str, v: &str)
tmpdir
fn tmpdir() -> Path
Returns the path to a temporary directory.
On Unix, returns the value of the 'TMPDIR' environment variable if it is set and non-empty and '/tmp' otherwise.
On Windows, returns the value of, in order, the 'TMP', 'TEMP', 'USERPROFILE' environment variable if any are set and not the empty string. Otherwise, tmpdir returns the path to the Windows directory.
waitpid
fn waitpid(pid: pid_t) -> c_int
walk_dir
fn walk_dir(p: &Path, f: &fn(&Path) -> bool)
Recursively walk a directory structure