Skip to content

Commit 8ee6bdd

Browse files
committed
redox: symlink and readlink
1 parent 3bfc18a commit 8ee6bdd

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/libstd/sys/redox/fs.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,12 +420,18 @@ fn remove_dir_all_recursive(path: &Path) -> io::Result<()> {
420420
}
421421

422422
pub fn readlink(p: &Path) -> io::Result<PathBuf> {
423-
canonicalize(p)
423+
let fd = cvt(syscall::open(p.to_str().unwrap(), syscall::O_SYMLINK | syscall::O_RDONLY))?;
424+
let mut buf: [u8; 4096] = [0; 4096];
425+
let count = cvt(syscall::read(fd, &mut buf))?;
426+
cvt(syscall::close(fd))?;
427+
Ok(PathBuf::from(unsafe { String::from_utf8_unchecked(Vec::from(&buf[..count])) }))
424428
}
425429

426-
pub fn symlink(_src: &Path, _dst: &Path) -> io::Result<()> {
427-
::sys_common::util::dumb_print(format_args!("Symlink\n"));
428-
unimplemented!();
430+
pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> {
431+
let fd = cvt(syscall::open(dst.to_str().unwrap(), syscall::O_SYMLINK | syscall::O_CREAT | syscall::O_WRONLY | 0o777))?;
432+
cvt(syscall::write(fd, src.to_str().unwrap().as_bytes()))?;
433+
cvt(syscall::close(fd))?;
434+
Ok(())
429435
}
430436

431437
pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> {

src/libstd/sys/redox/syscall/flag.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub const MAP_WRITE_COMBINE: usize = 2;
3333
pub const MODE_TYPE: u16 = 0xF000;
3434
pub const MODE_DIR: u16 = 0x4000;
3535
pub const MODE_FILE: u16 = 0x8000;
36+
pub const MODE_SYMLINK: u16 = 0xA000;
3637

3738
pub const MODE_PERM: u16 = 0x0FFF;
3839
pub const MODE_SETUID: u16 = 0o4000;
@@ -53,6 +54,7 @@ pub const O_TRUNC: usize = 0x0400_0000;
5354
pub const O_EXCL: usize = 0x0800_0000;
5455
pub const O_DIRECTORY: usize = 0x1000_0000;
5556
pub const O_STAT: usize = 0x2000_0000;
57+
pub const O_SYMLINK: usize = 0x4000_0000;
5658
pub const O_ACCMODE: usize = O_RDONLY | O_WRONLY | O_RDWR;
5759

5860
pub const SEEK_SET: usize = 0;

0 commit comments

Comments
 (0)