-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add unistd::getcwd and unistd::mkdir #416
Changes from 8 commits
ac64273
b03d4e5
8b1828a
8fbd8e9
c0a5785
50693c1
37e4f97
5f1e144
7dd12c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
extern crate tempdir; | ||
|
||
use nix::unistd::*; | ||
use nix::unistd::ForkResult::*; | ||
use nix::sys::wait::*; | ||
use nix::sys::stat; | ||
use std::iter; | ||
use std::ffi::CString; | ||
|
||
use std::io::{Write, Read}; | ||
use std::os::unix::prelude::*; | ||
use std::env::current_dir; | ||
use tempfile::tempfile; | ||
use tempdir::TempDir; | ||
use libc::off_t; | ||
use std::os::unix::prelude::*; | ||
|
||
|
||
|
||
#[test] | ||
fn test_fork_and_waitpid() { | ||
|
@@ -119,6 +122,24 @@ macro_rules! execve_test_factory( | |
) | ||
); | ||
|
||
#[test] | ||
fn test_getcwd() { | ||
let mut tmp_dir = TempDir::new("test_getcwd").unwrap().into_path(); | ||
assert!(chdir(tmp_dir.as_path()).is_ok()); | ||
assert_eq!(getcwd().unwrap(), current_dir().unwrap()); | ||
|
||
// make path 500 chars longer so that buffer doubling in getcwd kicks in. | ||
// Note: One path cannot be longer than 255 bytes (NAME_MAX) | ||
// whole path cannot be longer than PATH_MAX (usually 4096 on linux, 1024 on macos) | ||
for _ in 0..5 { | ||
let newdir = iter::repeat("a").take(100).collect::<String>(); | ||
tmp_dir.push(newdir); | ||
assert!(mkdir(tmp_dir.as_path(), stat::S_IRWXU).is_ok()); | ||
} | ||
assert!(chdir(tmp_dir.as_path()).is_ok()); | ||
assert_eq!(getcwd().unwrap(), current_dir().unwrap()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just noticed that this code is indented with 2-spaces for some reason. Should be 4. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Running |
||
} | ||
|
||
#[test] | ||
fn test_lseek() { | ||
const CONTENTS: &'static [u8] = b"abcdef123456"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous example included
extern crate
declarations and this one doesn't. I think they are not required in general for$crate
(nix here).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is required. The doc says:
Since I need to do a
extern crate tempdir
I also need to do an extern crate nix here.I think you want to hint that all examples should have the same style, that's why I now changed the doc of
getcwd
to have the same syntax asmkdir
(including extern crate nix and an explicit main function)