aboutsummaryrefslogtreecommitdiff
path: root/src/ffi.rs
diff options
context:
space:
mode:
authorJared Roesch <[email protected]>2014-10-11 01:50:34 -0700
committerJared Roesch <[email protected]>2014-10-11 01:57:33 -0700
commit5f017cd549b4c76849bfd5c33e6f6962acd89535 (patch)
tree4ea8770a90ca801e48e65032f756dccef069b5c5 /src/ffi.rs
parentMerge pull request #62 from vhbit/feature-matrix (diff)
downloadrust-openssl-5f017cd549b4c76849bfd5c33e6f6962acd89535.tar.xz
rust-openssl-5f017cd549b4c76849bfd5c33e6f6962acd89535.zip
Refactor init and error handling code
Move common ffi initialization code to 'ffi::init()' and the initialization of error handling to a a shared location.
Diffstat (limited to 'src/ffi.rs')
-rwxr-xr-xsrc/ffi.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/ffi.rs b/src/ffi.rs
index 0bdae5b6..46466d39 100755
--- a/src/ffi.rs
+++ b/src/ffi.rs
@@ -2,6 +2,7 @@
#![allow(dead_code)]
use libc::{c_void, c_int, c_char, c_ulong, c_long, c_uint, c_uchar, size_t};
use std::ptr;
+use sync::one::{Once, ONCE_INIT};
pub use bn::BIGNUM;
@@ -181,6 +182,17 @@ extern {}
#[link(name="wsock32")]
extern { }
+pub fn init() {
+ static mut INIT: Once = ONCE_INIT;
+
+ unsafe {
+ INIT.doit(|| {
+ SSL_library_init();
+ SSL_load_error_strings()
+ })
+ }
+}
+
// Functions converted from macros
pub unsafe fn BIO_eof(b: *mut BIO) -> bool {
BIO_ctrl(b, BIO_CTRL_EOF, 0, ptr::null_mut()) == 1