Skip to content

Instantly share code, notes, and snippets.

@wehlutyk
Created July 2, 2018 13:17
Show Gist options
  • Save wehlutyk/ba5c6a138da545a48a0328343c5c939a to your computer and use it in GitHub Desktop.
Save wehlutyk/ba5c6a138da545a48a0328343c5c939a to your computer and use it in GitHub Desktop.
diff --git a/miniz_oxide/src/lib.rs b/miniz_oxide/src/lib.rs
index 82fcd60..bde269f 100644
--- a/miniz_oxide/src/lib.rs
+++ b/miniz_oxide/src/lib.rs
@@ -22,7 +22,16 @@
//! ```
extern crate adler32;
+#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
extern crate libc;
+#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
+mod libc {
+ #![allow(non_camel_case_types)]
+ pub type c_void = u8;
+ pub type c_int = i32;
+ pub type c_uint = u32;
+ pub type c_ulong = u64;
+}
pub mod inflate;
pub mod deflate;
diff --git a/src/lib.rs b/src/lib.rs
index 6a71bcf..17ba6c8 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,28 @@
extern crate crc;
+#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))]
extern crate libc;
+#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
+mod libc {
+ #![allow(non_camel_case_types)]
+ pub type c_void = u8;
+ pub type c_int = i32;
+ pub type c_uint = u32;
+ pub type c_ulong = u64;
+ pub type c_char = i8;
+ pub type size_t = usize;
+
+ pub fn malloc(_: size_t) -> *mut c_void {
+ panic!()
+ }
+
+ pub fn realloc(_: *mut c_void, _: size_t) -> *mut c_void {
+ panic!()
+ }
+
+ pub fn free(_: *mut c_void) {
+ panic!()
+ }
+}
extern crate miniz_oxide;
use std::{cmp, ptr, slice};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment