about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPaul Dicker <pitdicker@gmail.com>2016-01-13 21:47:46 +0100
committerPaul Dicker <pitdicker@gmail.com>2016-01-13 21:47:46 +0100
commit7a1817c9d4a0649a7ea1c948bd731a5b63aa3d06 (patch)
tree2e1f2d70228636bb1ec4023e03adc422676ccf2c
parent42f4dd047af2de895df2754f7222b39f10cb6205 (diff)
downloadrust-7a1817c9d4a0649a7ea1c948bd731a5b63aa3d06.tar.gz
rust-7a1817c9d4a0649a7ea1c948bd731a5b63aa3d06.zip
Move `custom_flags` to `OpenOptionsExt`
And mark the new methods as unstable.
-rw-r--r--src/libstd/fs.rs39
-rw-r--r--src/libstd/sys/unix/ext/fs.rs28
-rw-r--r--src/libstd/sys/unix/fs.rs4
-rw-r--r--src/libstd/sys/windows/ext/fs.rs26
4 files changed, 58 insertions, 39 deletions
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs
index 7b2555ff1f5..6a96ab56fc3 100644
--- a/src/libstd/fs.rs
+++ b/src/libstd/fs.rs
@@ -519,46 +519,13 @@ impl OpenOptions {
     ///
     /// let file = OpenOptions::new().write(true).create_new(true).open("foo.txt");
     /// ```
-    #[stable(feature = "expand_open_options", since = "1.7.0")]
+    #[unstable(feature = "expand_open_options",
+               reason = "recently added",
+               issue = "30014")]
     pub fn create_new(&mut self, create_new: bool) -> &mut OpenOptions {
         self.0.create_new(create_new); self
     }
 
-    /// Pass custom open flags to the operating system.
-    ///
-    /// Windows and the various flavours of Unix support flags that are not
-    /// cross-platform, but that can be useful in some circumstances. On Unix they will
-    /// be passed as the variable _flags_ to `open`, on Windows as the
-    /// _dwFlagsAndAttributes_ parameter.
-    ///
-    /// The cross-platform options of Rust can do magic: they can set any flag necessary
-    /// to ensure it works as expected. For example, `.append(true)` on Unix not only
-    /// sets the flag `O_APPEND`, but also automatically `O_WRONLY` or `O_RDWR`. This
-    /// special treatment is not available for the custom flags.
-    ///
-    /// Custom flags can only set flags, not remove flags set by Rusts options.
-    ///
-    /// For the custom flags on Unix, the bits that define the access mode are masked
-    /// out with `O_ACCMODE`, to ensure they do not interfere with the access mode set
-    /// by Rusts options.
-    ///
-    /// # Examples
-    ///
-    /// ```rust,ignore
-    /// extern crate libc;
-    /// extern crate winapi;
-    /// use std::fs::OpenOptions;
-    ///
-    /// let options = OpenOptions::new().write(true);
-    /// if cfg!(unix) { options.custom_flags(libc::O_NOFOLLOW); }
-    /// if cfg!(windows) { options.custom_flags(winapi::FILE_FLAG_BACKUP_SEMANTICS); }
-    /// let file = options.open("foo.txt");
-    /// ```
-    #[stable(feature = "expand_open_options", since = "1.7.0")]
-    pub fn custom_flags(&mut self, flags: u32) -> &mut OpenOptions {
-        self.0.custom_flags(flags); self
-    }
-
     /// Opens a file at `path` with the options specified by `self`.
     ///
     /// # Errors
diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs
index 801b222b9a8..75ea5846fb3 100644
--- a/src/libstd/sys/unix/ext/fs.rs
+++ b/src/libstd/sys/unix/ext/fs.rs
@@ -104,6 +104,29 @@ pub trait OpenOptionsExt {
     /// the final permissions.
     #[stable(feature = "fs_ext", since = "1.1.0")]
     fn mode(&mut self, mode: raw::mode_t) -> &mut Self;
+
+    /// Pass custom flags to the `flags` agument of `open`.
+    ///
+    /// The bits that define the access mode are masked out with `O_ACCMODE`, to ensure
+    /// they do not interfere with the access mode set by Rusts options.
+    ///
+    /// Custom flags can only set flags, not remove flags set by Rusts options.
+    ///
+    /// # Examples
+    ///
+    /// ```no_run
+    /// extern crate libc;
+    /// use std::fs::OpenOptions;
+    /// use std::os::unix::fs::OpenOptionsExt;
+    ///
+    /// let options = OpenOptions::new().write(true);
+    /// if cfg!(unix) { options.custom_flags(libc::O_NOFOLLOW); }
+    /// let file = options.open("foo.txt");
+    /// ```
+    #[unstable(feature = "expand_open_options",
+               reason = "recently added",
+               issue = "30014")]
+    fn custom_flags(&mut self, flags: i32) -> &mut Self;
 }
 
 #[stable(feature = "fs_ext", since = "1.1.0")]
@@ -111,6 +134,10 @@ impl OpenOptionsExt for OpenOptions {
     fn mode(&mut self, mode: raw::mode_t) -> &mut OpenOptions {
         self.as_inner_mut().mode(mode); self
     }
+
+    fn custom_flags(&mut self, flags: i32) -> &mut OpenOptions {
+        self.as_inner_mut().custom_flags(flags); self
+    }
 }
 
 // Hm, why are there casts here to the returned type, shouldn't the types always
@@ -265,4 +292,3 @@ impl DirBuilderExt for fs::DirBuilder {
         self
     }
 }
-
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs
index c6a02f2b8b9..31ea6b7dd2e 100644
--- a/src/libstd/sys/unix/fs.rs
+++ b/src/libstd/sys/unix/fs.rs
@@ -58,7 +58,7 @@ pub struct OpenOptions {
     create: bool,
     create_new: bool,
     // system-specific
-    custom_flags: u32,
+    custom_flags: i32,
     mode: mode_t,
 }
 
@@ -259,7 +259,7 @@ impl OpenOptions {
     pub fn create(&mut self, create: bool) { self.create = create; }
     pub fn create_new(&mut self, create_new: bool) { self.create_new = create_new; }
 
-    pub fn custom_flags(&mut self, flags: u32) { self.custom_flags = flags; }
+    pub fn custom_flags(&mut self, flags: i32) { self.custom_flags = flags; }
     pub fn mode(&mut self, mode: raw::mode_t) { self.mode = mode as mode_t; }
 
     fn get_access_mode(&self) -> io::Result<c_int> {
diff --git a/src/libstd/sys/windows/ext/fs.rs b/src/libstd/sys/windows/ext/fs.rs
index fa7e0e564ac..04053b6cb6a 100644
--- a/src/libstd/sys/windows/ext/fs.rs
+++ b/src/libstd/sys/windows/ext/fs.rs
@@ -64,6 +64,28 @@ pub trait OpenOptionsExt {
     /// ```
     fn share_mode(&mut self, val: u32) -> &mut Self;
 
+    /// Sets extra flags for the `dwFileFlags` argument to the call to `CreateFile2`
+    /// (or combines it with `attributes` and `security_qos_flags` to set the
+    /// `dwFlagsAndAttributes` for `CreateFile`).
+    ///
+    /// Custom flags can only set flags, not remove flags set by Rusts options.
+    ///
+    /// # Examples
+    ///
+    /// ```rust,ignore
+    /// extern crate winapi;
+    /// use std::fs::OpenOptions;
+    /// use std::os::windows::fs::OpenOptionsExt;
+    ///
+    /// let options = OpenOptions::new().create(true).write(true);
+    /// if cfg!(windows) { options.custom_flags(winapi::FILE_FLAG_DELETE_ON_CLOSE); }
+    /// let file = options.open("foo.txt");
+    /// ```
+    #[unstable(feature = "expand_open_options",
+               reason = "recently added",
+               issue = "30014")]
+    fn custom_flags(&mut self, flags: u32) -> &mut Self;
+
     /// Sets the `dwFileAttributes` argument to the call to `CreateFile2` to
     /// the specified value (or combines it with `custom_flags` and
     /// `security_qos_flags` to set the `dwFlagsAndAttributes` for `CreateFile`).
@@ -114,6 +136,10 @@ impl OpenOptionsExt for OpenOptions {
         self.as_inner_mut().share_mode(share); self
     }
 
+    fn custom_flags(&mut self, flags: u32) -> &mut OpenOptions {
+        self.as_inner_mut().custom_flags(flags); self
+    }
+
     fn attributes(&mut self, attributes: u32) -> &mut OpenOptions {
         self.as_inner_mut().attributes(attributes); self
     }