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
MapError
MapOption
MemoryMapKind
MemoryMap
Pipe
of to_str::ToStr for MapError
for MemoryMap
of Drop for MemoryMap
args
- Returns the arguments which this program was started with (normally passed via the command line).change_dir
close
- Delegates to the libc close() function, returning the same return value.copy_file
- Copies a file from one location to anotherdll_filename
- Returns the proper dll filename for the given basename of a file.env
- Returns a vector of (variable, value) pairs for all the environment variables of the current process.errno
- Returns the platform-specific value of errnofdopen
fill_charp_buf
fsync_fd
getcwd
getenv
- Fetches the environment variable n
from the current process, returning None if the variable isn't set.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 directorymake_absolute
- Convert a relative path to an absolute pathmake_dir
- Creates a directory at the specified pathmkdir_recursive
- Creates a directory with a given modepage_size
path_exists
- Indicates whether a path existspath_is_dir
- Indicates whether a path represents a directorypipe
remove_dir
- Removes a directory at the specified pathremove_dir_recursive
- Removes a directory at the specified path, after removing all its contentsremove_file
- Deletes an existing filerename_file
- Renames an existing file or directoryself_exe_path
- Optionally returns the filesystem path to the current executable which is runningset_exit_status
- Sets the process exit codesetenv
- Sets the environment variable n
to the value v
for the currently running processtmpdir
- Returns the path to a temporary directory.unsetenv
- Remove a variable from the environment entirelywalk_dir
- Recursively walk a directory structureos::consts
os::rustrt
TMPBUF_SZ
uint
MapError
ErrFdNotAvail
ErrInvalidFd
ErrUnaligned
ErrNoMapSupport
ErrNoMem
ErrUnknown(libc::c_int)
ErrUnsupProt
ErrUnsupOffset
ErrAlreadyExists
ErrVirtualAlloc(uint)
ErrCreateFileMappingW(uint)
ErrMapViewOfFile(uint)
MapOption
MapReadable
MapWritable
MapExecutable
MapAddr(*c_void)
MapFd(c_int)
MapOffset(uint)
MemoryMapKind
MapFile(*c_void)
MapVirtual
MemoryMap
pub struct MemoryMap {
data: *mut u8,
len: size_t,
kind: MemoryMapKind,
}
Pipe
pub struct Pipe {
input: c_int,
out: c_int,
}
to_str::ToStr
for MapError
to_str
fn to_str(&self) -> ~str
MemoryMap
new
fn new(min_len: uint, options: ~[MapOption]) -> Result<~MemoryMap, MapError>
granularity
fn granularity() -> uint
Drop
for MemoryMap
drop
fn drop(&self)
args
fn args() -> ~[~str]
Returns the arguments which this program was started with (normally passed via the command line).
change_dir
fn change_dir(p: &Path) -> bool
Changes the current working directory to the specified path, returning whether the change was completed successfully or not.
close
fn close(fd: c_int) -> c_int
Delegates to the libc close() function, returning the same return value.
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
Returns the proper dll filename for the given basename of a file.
env
fn env() -> ~[(~str, ~str)]
Returns a vector of (variable, value) pairs for all the environment variables of the current process.
errno
fn errno() -> int
Returns the platform-specific value of errno
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>
Fetches the environment variable n
from the current process, returning None if the variable isn't set.
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.
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
mkdir_recursive
fn mkdir_recursive(p: &Path, mode: c_int) -> bool
Creates a directory with a given mode. Returns true iff creation succeeded. Also creates all intermediate subdirectories if they don't already exist, giving all of them the same mode.
page_size
fn page_size() -> uint
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() -> Pipe
remove_dir
fn remove_dir(p: &Path) -> bool
Removes a directory at the specified path
remove_dir_recursive
fn remove_dir_recursive(p: &Path) -> bool
Removes a directory at the specified path, after removing all its contents. Use carefully!
remove_file
fn remove_file(p: &Path) -> bool
Deletes an existing file
rename_file
fn rename_file(old: &Path, new: &Path) -> bool
Renames an existing file or directory
self_exe_path
fn self_exe_path() -> Option<Path>
Optionally returns the filesystem path to the current executable which is running. If any failure occurs, None is returned.
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)
Sets the environment variable n
to the value v
for the currently running process
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 Android, there is no global temporary folder (it is usually allocated per-app), hence returns '/data/tmp' which is commonly used.
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.
unsetenv
fn unsetenv(n: &str)
Remove a variable from the environment entirely
walk_dir
fn walk_dir(p: &Path, f: &fn(&Path) -> bool) -> bool
Recursively walk a directory structure