From: Alex Crichton Date: Wed, 29 Apr 2015 22:48:38 +0000 (-0700) Subject: rollup merge of #24873: alexcrichton/fix-windows-stdio X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=cc04cd4bb169141c12b1f44ea75f265826dfbda9;p=rust.git rollup merge of #24873: alexcrichton/fix-windows-stdio Conflicts: src/libstd/sys/windows/fs2.rs --- cc04cd4bb169141c12b1f44ea75f265826dfbda9 diff --cc src/libstd/sys/windows/fs2.rs index 5b748280986,1c47176173a..03a56e2958a --- a/src/libstd/sys/windows/fs2.rs +++ b/src/libstd/sys/windows/fs2.rs @@@ -310,40 -268,7 +314,42 @@@ impl File pub fn handle(&self) -> &Handle { &self.handle } + fn is_symlink(&self) -> bool { + self.readlink().is_ok() + } + + fn readlink(&self) -> io::Result { + let mut space = [0u8; c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; + let mut bytes = 0; + + unsafe { + try!(cvt({ + c::DeviceIoControl(self.handle.raw(), + c::FSCTL_GET_REPARSE_POINT, + 0 as *mut _, + 0, + space.as_mut_ptr() as *mut _, + space.len() as libc::DWORD, + &mut bytes, + 0 as *mut _) + })); + let buf: *const c::REPARSE_DATA_BUFFER = space.as_ptr() as *const _; + if (*buf).ReparseTag != c::IO_REPARSE_TAG_SYMLINK { + return Err(io::Error::new(io::ErrorKind::Other, "not a symlink")) + } + let info: *const c::SYMBOLIC_LINK_REPARSE_BUFFER = + &(*buf).rest as *const _ as *const _; + let path_buffer = &(*info).PathBuffer as *const _ as *const u16; + let subst_off = (*info).SubstituteNameOffset / 2; + let subst_ptr = path_buffer.offset(subst_off as isize); + let subst_len = (*info).SubstituteNameLength / 2; + let subst = slice::from_raw_parts(subst_ptr, subst_len as usize); + + Ok(PathBuf::from(OsString::from_wide(subst))) + } + } ++ + pub fn into_handle(self) -> Handle { self.handle } } impl FromInner for File {