Implement posix_memalign
This commit is contained in:
@@ -582,6 +582,27 @@ pub extern "C" fn nrand48(xsubi: [c_ushort; 3]) -> c_long {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn posix_memalign(memptr: *mut *mut c_void, alignment: size_t, size: size_t) -> c_int {
|
||||
const void_ptr_size: usize = mem::size_of::<*mut c_void>();
|
||||
|
||||
/* Check that alignment is:
|
||||
* a) a multiple of sizeof(void *)
|
||||
* b) a power-of-two multiple of sizeof(void *). Integer division as
|
||||
* below gives the correct result once a) is ensured. */
|
||||
if alignment % void_ptr_size == 0 && (alignment/void_ptr_size).is_power_of_two() {
|
||||
let ptr = platform::alloc_align(size, alignment);
|
||||
if !ptr.is_null() {
|
||||
*memptr = ptr;
|
||||
0
|
||||
} else {
|
||||
ENOMEM
|
||||
}
|
||||
} else {
|
||||
EINVAL
|
||||
}
|
||||
}
|
||||
|
||||
// #[no_mangle]
|
||||
pub extern "C" fn ptsname(fildes: c_int) -> *mut c_char {
|
||||
unimplemented!();
|
||||
|
||||
Reference in New Issue
Block a user