Skip to content

Commit f070de8

Browse files
Daniel Pattersonbrson
authored andcommitted
---
yaml --- r: 29956 b: refs/heads/incoming c: 3f1f6bf h: refs/heads/master v: v3
1 parent 6d6594b commit f070de8

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 47cca22d5455d2d60226ead907fd627784701ef5
9+
refs/heads/incoming: 3f1f6bf9e3fc7d07adedef225e33156425a0608f
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/src/libcore/os.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export close, fclose, fsync_fd, waitpid;
3030
export env, getenv, setenv, fdopen, pipe;
3131
export getcwd, dll_filename, self_exe_path;
3232
export exe_suffix, dll_suffix, sysname, arch, family;
33-
export homedir, list_dir, list_dir_path, path_is_dir, path_exists,
33+
export homedir, tmpdir, list_dir, list_dir_path, path_is_dir, path_exists,
3434
make_absolute, make_dir, remove_dir, change_dir, remove_file,
3535
copy_file;
3636
export last_os_error;
@@ -464,6 +464,43 @@ fn homedir() -> option<Path> {
464464
}
465465
}
466466

467+
/**
468+
* Returns the path to a temporary directory, if known.
469+
*
470+
* On Unix, returns the value of the 'TMPDIR' environment variable if it is
471+
* set and non-empty and '/tmp' otherwise.
472+
*
473+
* On Windows, returns the value of, in order, the 'TMP', 'TEMP',
474+
* 'USERPROFILE' environment variable if any are set and not the empty
475+
* string. Otherwise, tmpdir returns option::none.
476+
*/
477+
fn tmpdir() -> option<Path> {
478+
return lookup();
479+
480+
fn getenv_nonempty(v: Path) -> option<Path> {
481+
match getenv(v) {
482+
some(x) =>
483+
if str::is_empty(x) {
484+
none
485+
} else {
486+
some(x)
487+
},
488+
_ => none
489+
}
490+
}
491+
492+
#[cfg(unix)]
493+
fn lookup() -> option<Path> {
494+
option::or(getenv_nonempty(~"TMPDIR"), some(~"/tmp"))
495+
}
496+
497+
#[cfg(windows)]
498+
fn lookup() -> option<Path> {
499+
option::or(getenv_nonempty(~"TMP"),
500+
option::or(getenv_nonempty(~"TEMP"),
501+
getenv_nonempty(~"USERPROFILE")))
502+
}
503+
}
467504
/// Recursively walk a directory structure
468505
fn walk_dir(p: Path, f: fn(Path) -> bool) {
469506

0 commit comments

Comments
 (0)