relibc: P3-semaphore-varargs-header — apply Phase 0e patch
This commit is contained in:
@@ -3,6 +3,9 @@ include_guard = "_RELIBC_SEMAPHORE_H"
|
||||
after_includes = """
|
||||
#include <bits/timespec.h> // for timespec
|
||||
"""
|
||||
trailer = """
|
||||
#define SEM_FAILED ((sem_t *) -1)
|
||||
"""
|
||||
language = "C"
|
||||
style = "Type"
|
||||
no_includes = true
|
||||
|
||||
@@ -144,7 +144,8 @@ pub unsafe extern "C" fn sem_init(sem: *mut sem_t, _pshared: c_int, value: c_uin
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn sem_open(
|
||||
name: *const c_char,
|
||||
oflag: c_int, /* (va_list) mode: mode_t, value: c_uint */
|
||||
oflag: c_int,
|
||||
mut __valist: ...
|
||||
) -> *mut sem_t {
|
||||
if name.is_null() { ERRNO.set(EINVAL); return SEM_FAILED_PTR; }
|
||||
let name_bytes = unsafe { CStr::from_ptr(name) }.to_bytes().to_vec();
|
||||
@@ -156,11 +157,10 @@ pub unsafe extern "C" fn sem_open(
|
||||
with_named_sems(|map| { if let Some(e) = map.get(&name_bytes) { e.refs.fetch_add(1, Ordering::Relaxed); } });
|
||||
return ptr as *mut NamedSemaphore as *mut sem_t;
|
||||
}
|
||||
let (mode, value): (mode_t, c_uint) = {
|
||||
let oflag_ptr: *const c_int = &oflag;
|
||||
let mode_ptr = unsafe { oflag_ptr.add(1) as *const mode_t };
|
||||
let value_ptr = unsafe { oflag_ptr.add(2) as *const c_uint };
|
||||
(unsafe { *mode_ptr }, if create { unsafe { *value_ptr } } else { 0 })
|
||||
let (mode, value): (mode_t, c_uint) = if create {
|
||||
(unsafe { __valist.arg::<mode_t>() }, unsafe { __valist.arg::<c_uint>() })
|
||||
} else {
|
||||
(0, 0)
|
||||
};
|
||||
let ptr = unsafe { map_named_semaphore(name, oflag, mode, value) };
|
||||
if ptr == SEM_FAILED_PTR { return SEM_FAILED_PTR; }
|
||||
|
||||
Reference in New Issue
Block a user