summaryrefslogtreecommitdiffstats
path: root/vendor/fd-lock/src/sys/windows/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/fd-lock/src/sys/windows/utils.rs')
-rw-r--r--vendor/fd-lock/src/sys/windows/utils.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/vendor/fd-lock/src/sys/windows/utils.rs b/vendor/fd-lock/src/sys/windows/utils.rs
new file mode 100644
index 000000000..43656a083
--- /dev/null
+++ b/vendor/fd-lock/src/sys/windows/utils.rs
@@ -0,0 +1,33 @@
+use std::io;
+use std::mem;
+
+use windows_sys::Win32::Foundation::BOOL;
+use windows_sys::Win32::System::IO::OVERLAPPED;
+
+/// A wrapper around `OVERLAPPED` to provide "rustic" accessors and
+/// initializers.
+pub(crate) struct Overlapped(OVERLAPPED);
+
+impl Overlapped {
+ /// Creates a new zeroed out instance of an overlapped I/O tracking state.
+ ///
+ /// This is suitable for passing to methods which will then later get
+ /// notified via an I/O Completion Port.
+ pub(crate) fn zero() -> Overlapped {
+ Overlapped(unsafe { mem::zeroed() })
+ }
+
+ /// Gain access to the raw underlying data
+ pub(crate) fn raw(&self) -> *mut OVERLAPPED {
+ &self.0 as *const _ as *mut _
+ }
+}
+
+/// Convert a system call which returns a `BOOL` to an `io::Result`.
+pub(crate) fn syscall(status: BOOL) -> std::io::Result<()> {
+ if status == 0 {
+ Err(io::Error::last_os_error())
+ } else {
+ Ok(())
+ }
+}