diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/same-file/examples | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/same-file/examples')
-rw-r--r-- | third_party/rust/same-file/examples/is_same_file.rs | 13 | ||||
-rw-r--r-- | third_party/rust/same-file/examples/is_stderr.rs | 33 |
2 files changed, 46 insertions, 0 deletions
diff --git a/third_party/rust/same-file/examples/is_same_file.rs b/third_party/rust/same-file/examples/is_same_file.rs new file mode 100644 index 0000000000..451a6af89c --- /dev/null +++ b/third_party/rust/same-file/examples/is_same_file.rs @@ -0,0 +1,13 @@ +extern crate same_file; + +use std::error::Error; +use same_file::is_same_file; + +fn try_main() -> Result<(), Box<Error>> { + assert!(is_same_file("/bin/sh", "/usr/bin/sh")?); + Ok(()) +} + +fn main() { + try_main().unwrap(); +} diff --git a/third_party/rust/same-file/examples/is_stderr.rs b/third_party/rust/same-file/examples/is_stderr.rs new file mode 100644 index 0000000000..ec2f98794c --- /dev/null +++ b/third_party/rust/same-file/examples/is_stderr.rs @@ -0,0 +1,33 @@ +extern crate same_file; + +use std::io; +use std::process; + +use same_file::Handle; + +fn main() { + if let Err(err) = run() { + println!("{}", err); + process::exit(1); + } +} + +fn run() -> io::Result<()> { + // Run with `cargo run is_stderr 2> examples/stderr` to see + // interesting output. + let candidates = &[ + "examples/is_same_file.rs", + "examples/is_stderr.rs", + "examples/stderr", + ]; + let stderr_handle = Handle::stderr()?; + for candidate in candidates { + let handle = Handle::from_path(candidate)?; + if stderr_handle == handle { + println!("{:?} is stderr!", candidate); + } else { + println!("{:?} is NOT stderr!", candidate); + } + } + Ok(()) +} |