diff options
| author | Jared Roesch <[email protected]> | 2014-10-11 01:50:34 -0700 |
|---|---|---|
| committer | Jared Roesch <[email protected]> | 2014-10-11 01:57:33 -0700 |
| commit | 5f017cd549b4c76849bfd5c33e6f6962acd89535 (patch) | |
| tree | 4ea8770a90ca801e48e65032f756dccef069b5c5 /src/ffi.rs | |
| parent | Merge pull request #62 from vhbit/feature-matrix (diff) | |
| download | rust-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-x | src/ffi.rs | 12 |
1 files changed, 12 insertions, 0 deletions
@@ -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 |