Skip to content

Commit 3a1bb2b

Browse files
committed
Use O_DIRECTORY
1 parent 6733074 commit 3a1bb2b

File tree

1 file changed

+12
-9
lines changed
  • src/libstd/sys/redox

1 file changed

+12
-9
lines changed

src/libstd/sys/redox/fs.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ impl DirBuilder {
339339
}
340340

341341
pub fn mkdir(&self, p: &Path) -> io::Result<()> {
342-
cvt(libc::mkdir(p.to_str().unwrap(), self.mode))?;
342+
let fd = cvt(libc::open(p.to_str().unwrap(), libc::O_CREAT | libc::O_DIRECTORY | libc::O_EXCL | (self.mode as usize & 0o777)))?;
343+
let _ = libc::close(fd);
343344
Ok(())
344345
}
345346

@@ -372,11 +373,12 @@ impl fmt::Debug for File {
372373

373374
pub fn readdir(p: &Path) -> io::Result<ReadDir> {
374375
let root = Arc::new(p.to_path_buf());
375-
let mut options = OpenOptions::new();
376-
options.read(true);
377-
let fd = File::open(p, &options)?;
376+
377+
let fd = cvt(open(p.to_str().unwrap(), libc::O_CLOEXEC | libc::O_RDONLY | libc::O_DIRECTORY))?;
378+
let file = FileDesc::new(fd);
378379
let mut data = Vec::new();
379-
fd.read_to_end(&mut data)?;
380+
file.read_to_end(&mut data)?;
381+
380382
Ok(ReadDir { data: data, i: 0, root: root })
381383
}
382384

@@ -437,10 +439,11 @@ pub fn link(_src: &Path, _dst: &Path) -> io::Result<()> {
437439

438440
pub fn stat(p: &Path) -> io::Result<FileAttr> {
439441
let mut stat: stat = stat::default();
440-
let mut options = OpenOptions::new();
441-
options.read(true);
442-
let file = File::open(p, &options)?;
443-
cvt(fstat(file.0.raw(), &mut stat))?;
442+
443+
let fd = cvt(open(p.to_str().unwrap(), libc::O_CLOEXEC | libc::O_STAT))?;
444+
cvt(fstat(fd, &mut stat))?;
445+
let _ = libc::close(fd);
446+
444447
Ok(FileAttr { stat: stat })
445448
}
446449

0 commit comments

Comments
 (0)