Skip to content

Instantly share code, notes, and snippets.

@thomcc
Created June 9, 2018 02:36
Show Gist options
  • Save thomcc/95cb28cf3dd08f3e01a4cddc06205d61 to your computer and use it in GitHub Desktop.
Save thomcc/95cb28cf3dd08f3e01a4cddc06205d61 to your computer and use it in GitHub Desktop.
#[cfg(feature = "sqlcipher")]
#[link(name = "sqlcipher")]
extern "C" {
fn sqlite3_key(
db: *mut ::std::os::raw::c_void,
p_key: *const ::std::os::raw::c_void,
n_key: ::std::os::raw::c_int
) -> ::std::os::raw::c_int;
}
#[cfg(feature = "sqlcipher")]
#[inline(never)]
fn hacky_ensure_sqlcipher_exists() {
use std::ptr;
// Use the address of sqlite3_key here, and write it into a volatile "buffer".
// This is a crude way of forcing a linking failure if sqlite3_key is not
// available, without requiring us actually call sqlite3_key.
let p = (&sqlite3_key as *const _) as usize;
let mut dest: usize = 0;
unsafe {
ptr::write_volatile(&mut dest as *mut usize, p);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment