pub use self::imp::Lock;
+
#[cfg(unix)]
mod imp {
- use std::libc;
+ use libc;
#[cfg(target_os = "linux")]
mod os {
- use std::libc;
+ use libc;
pub struct flock {
- l_type: libc::c_short,
- l_whence: libc::c_short,
- l_start: libc::off_t,
- l_len: libc::off_t,
- l_pid: libc::pid_t,
+ pub l_type: libc::c_short,
+ pub l_whence: libc::c_short,
+ pub l_start: libc::off_t,
+ pub l_len: libc::off_t,
+ pub l_pid: libc::pid_t,
// not actually here, but brings in line with freebsd
- l_sysid: libc::c_int,
+ pub l_sysid: libc::c_int,
}
pub static F_WRLCK: libc::c_short = 1;
#[cfg(target_os = "freebsd")]
mod os {
- use std::libc;
+ use libc;
pub struct flock {
- l_start: libc::off_t,
- l_len: libc::off_t,
- l_pid: libc::pid_t,
- l_type: libc::c_short,
- l_whence: libc::c_short,
- l_sysid: libc::c_int,
+ pub l_start: libc::off_t,
+ pub l_len: libc::off_t,
+ pub l_pid: libc::pid_t,
+ pub l_type: libc::c_short,
+ pub l_whence: libc::c_short,
+ pub l_sysid: libc::c_int,
}
pub static F_UNLCK: libc::c_short = 2;
pub static F_SETLKW: libc::c_int = 13;
}
+ #[cfg(target_os = "dragonfly")]
+ mod os {
+ use libc;
+
+ pub struct flock {
+ pub l_start: libc::off_t,
+ pub l_len: libc::off_t,
+ pub l_pid: libc::pid_t,
+ pub l_type: libc::c_short,
+ pub l_whence: libc::c_short,
+
+ // not actually here, but brings in line with freebsd
+ pub l_sysid: libc::c_int,
+ }
+
+ pub static F_UNLCK: libc::c_short = 2;
+ pub static F_WRLCK: libc::c_short = 3;
+ pub static F_SETLK: libc::c_int = 8;
+ pub static F_SETLKW: libc::c_int = 9;
+ }
+
#[cfg(target_os = "macos")]
+ #[cfg(target_os = "ios")]
mod os {
- use std::libc;
+ use libc;
pub struct flock {
- l_start: libc::off_t,
- l_len: libc::off_t,
- l_pid: libc::pid_t,
- l_type: libc::c_short,
- l_whence: libc::c_short,
+ pub l_start: libc::off_t,
+ pub l_len: libc::off_t,
+ pub l_pid: libc::pid_t,
+ pub l_type: libc::c_short,
+ pub l_whence: libc::c_short,
// not actually here, but brings in line with freebsd
- l_sysid: libc::c_int,
+ pub l_sysid: libc::c_int,
}
pub static F_UNLCK: libc::c_short = 2;
}
pub struct Lock {
- priv fd: libc::c_int,
+ fd: libc::c_int,
}
impl Lock {
l_sysid: 0,
};
let ret = unsafe {
- libc::fcntl(fd, os::F_SETLKW, &flock as *os::flock)
+ libc::fcntl(fd, os::F_SETLKW, &flock as *const os::flock)
};
if ret == -1 {
unsafe { libc::close(fd); }
l_sysid: 0,
};
unsafe {
- libc::fcntl(self.fd, os::F_SETLK, &flock as *os::flock);
+ libc::fcntl(self.fd, os::F_SETLK, &flock as *const os::flock);
libc::close(self.fd);
}
}
#[cfg(windows)]
mod imp {
- use std::libc;
+ use libc;
use std::mem;
- use std::os::win32::as_utf16_p;
use std::os;
use std::ptr;
static LOCKFILE_EXCLUSIVE_LOCK: libc::DWORD = 0x00000002;
+ #[allow(non_snake_case_functions)]
extern "system" {
fn LockFileEx(hFile: libc::HANDLE,
dwFlags: libc::DWORD,
}
pub struct Lock {
- priv handle: libc::HANDLE,
+ handle: libc::HANDLE,
}
impl Lock {
pub fn new(p: &Path) -> Lock {
- let handle = as_utf16_p(p.as_str().unwrap(), |p| unsafe {
- libc::CreateFileW(p,
+ let p_16: Vec<u16> = p.as_str().unwrap().utf16_units().collect();
+ let p_16 = p_16.append_one(0);
+ let handle = unsafe {
+ libc::CreateFileW(p_16.as_ptr(),
libc::FILE_GENERIC_READ |
libc::FILE_GENERIC_WRITE,
libc::FILE_SHARE_READ |
libc::CREATE_ALWAYS,
libc::FILE_ATTRIBUTE_NORMAL,
ptr::mut_null())
- });
+ };
if handle as uint == libc::INVALID_HANDLE_VALUE as uint {
fail!("create file error: {}", os::last_os_error());
}
- let mut overlapped: libc::OVERLAPPED = unsafe { mem::init() };
+ let mut overlapped: libc::OVERLAPPED = unsafe { mem::zeroed() };
let ret = unsafe {
LockFileEx(handle, LOCKFILE_EXCLUSIVE_LOCK, 0, 100, 0,
&mut overlapped)
impl Drop for Lock {
fn drop(&mut self) {
- let mut overlapped: libc::OVERLAPPED = unsafe { mem::init() };
+ let mut overlapped: libc::OVERLAPPED = unsafe { mem::zeroed() };
unsafe {
UnlockFileEx(self.handle, 0, 100, 0, &mut overlapped);
libc::CloseHandle(self.handle);