1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#![warn(missing_docs)]
#![cfg_attr(feature = "strict", deny(warnings))]
#![no_std]

//! libc crate

#[macro_use]
extern crate cfg_if;

cfg_if! {
	if #[cfg(feature="ext_memops")] {
		extern "C" {
			fn ext_memcmp(cx: *const u8, ct: *const u8, n: usize) -> i32;
			fn ext_memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8;
			fn ext_memmove(dest: *mut u8, src: *const u8, n: usize) -> *mut u8;
			fn ext_memset(dest: *mut u8, c: i32, n: usize) -> *mut u8;
		}

		// Declaring these function here prevents Emscripten from including it's own verisons
		// into final binary.

		/// memcmp extern
		#[no_mangle]
		pub unsafe extern "C" fn memcmp(cx: *const u8, ct: *const u8, n: usize) -> i32 {
			ext_memcmp(cx, ct, n)
		}

		/// memcpy extern
		#[no_mangle]
		pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 {
			ext_memcpy(dest, src, n)
		}

		/// memmove extern
		#[no_mangle]
		pub unsafe extern "C" fn memmove(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 {
			ext_memmove(dest, src, n)
		}

		/// memset extern
		#[no_mangle]
		pub unsafe extern "C" fn memset(dest: *mut u8, c: i32, n: usize) -> *mut u8 {
			ext_memset(dest, c, n)
		}
	}
}