From 62ec4789989d19084f368dd0e42cbe662942716f Mon Sep 17 00:00:00 2001 From: Nikolay Amiantov Date: Fri, 19 Feb 2016 17:22:50 +0300 Subject: [PATCH] mqueue: change types to allow more cases --- src/mqueue.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mqueue.rs b/src/mqueue.rs index bc3eca2cc1..91ac6e60a6 100644 --- a/src/mqueue.rs +++ b/src/mqueue.rs @@ -4,9 +4,10 @@ use {Errno, Result}; -use libc::{c_int, c_long, c_char, size_t, mode_t, strlen}; +use libc::{c_int, c_long, c_char, size_t, mode_t}; use std::ffi::CString; use sys::stat::Mode; +use std::ptr; pub use self::consts::*; @@ -75,9 +76,9 @@ impl MqAttr { } -#[inline] -pub fn mq_open(name: &CString, oflag: MQ_OFlag, mode: Mode, attr: &MqAttr) -> Result { - let res = unsafe { ffi::mq_open(name.as_ptr(), oflag.bits(), mode.bits() as mode_t, attr as *const MqAttr) }; +pub fn mq_open(name: &CString, oflag: MQ_OFlag, mode: Mode, attr: Option<&MqAttr>) -> Result { + let attr_p = attr.map(|attr| attr as *const _).unwrap_or(ptr::null()); + let res = unsafe { ffi::mq_open(name.as_ptr(), oflag.bits(), mode.bits() as mode_t, attr_p) }; Errno::result(res) } @@ -100,11 +101,10 @@ pub fn mq_receive(mqdes: MQd, message: &mut [u8], msq_prio: u32) -> Result Result { - let len = unsafe { strlen(message.as_ptr()) as size_t }; - let res = unsafe { ffi::mq_send(mqdes, message.as_ptr(), len, msq_prio) }; +pub fn mq_send(mqdes: MQd, message: &[u8], msq_prio: u32) -> Result<()> { + let res = unsafe { ffi::mq_send(mqdes, message.as_ptr() as *const c_char, message.len(), msq_prio) }; - Errno::result(res).map(|r| r as usize) + Errno::result(res).map(drop) } pub fn mq_getattr(mqd: MQd) -> Result {