Skip to content

Commit

Permalink
Rollup merge of rust-lang#42975 - ids1024:symlink2, r=aturon
Browse files Browse the repository at this point in the history
redox: symlink and readlink
  • Loading branch information
Mark-Simulacrum authored Jul 4, 2017
2 parents 93e46a9 + 3456608 commit 8abc58e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/libstd/sys/redox/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,19 @@ fn remove_dir_all_recursive(path: &Path) -> io::Result<()> {
}

pub fn readlink(p: &Path) -> io::Result<PathBuf> {
canonicalize(p)
}

pub fn symlink(_src: &Path, _dst: &Path) -> io::Result<()> {
::sys_common::util::dumb_print(format_args!("Symlink\n"));
unimplemented!();
let fd = cvt(syscall::open(p.to_str().unwrap(), syscall::O_SYMLINK | syscall::O_RDONLY))?;
let mut buf: [u8; 4096] = [0; 4096];
let count = cvt(syscall::read(fd, &mut buf))?;
cvt(syscall::close(fd))?;
Ok(PathBuf::from(unsafe { String::from_utf8_unchecked(Vec::from(&buf[..count])) }))
}

pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> {
let fd = cvt(syscall::open(dst.to_str().unwrap(),
syscall::O_SYMLINK | syscall::O_CREAT | syscall::O_WRONLY | 0o777))?;
cvt(syscall::write(fd, src.to_str().unwrap().as_bytes()))?;
cvt(syscall::close(fd))?;
Ok(())
}

pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> {
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/sys/redox/syscall/flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub const MAP_WRITE_COMBINE: usize = 2;
pub const MODE_TYPE: u16 = 0xF000;
pub const MODE_DIR: u16 = 0x4000;
pub const MODE_FILE: u16 = 0x8000;
pub const MODE_SYMLINK: u16 = 0xA000;

pub const MODE_PERM: u16 = 0x0FFF;
pub const MODE_SETUID: u16 = 0o4000;
Expand All @@ -53,6 +54,7 @@ pub const O_TRUNC: usize = 0x0400_0000;
pub const O_EXCL: usize = 0x0800_0000;
pub const O_DIRECTORY: usize = 0x1000_0000;
pub const O_STAT: usize = 0x2000_0000;
pub const O_SYMLINK: usize = 0x4000_0000;
pub const O_ACCMODE: usize = O_RDONLY | O_WRONLY | O_RDWR;

pub const SEEK_SET: usize = 0;
Expand Down

0 comments on commit 8abc58e

Please sign in to comment.