diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2016-03-07 15:42:29 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2016-03-12 12:31:13 -0800 |
| commit | b53764c73bd722ea22142bace6249d5950066253 (patch) | |
| tree | ecf0066dbdb65bf0cf4600c4560d06edcacff707 /src/libstd/sys/windows/dynamic_lib.rs | |
| parent | 083db64d9050ae6f92628aa869171ac4affb016f (diff) | |
| download | rust-b53764c73bd722ea22142bace6249d5950066253.tar.gz rust-b53764c73bd722ea22142bace6249d5950066253.zip | |
std: Clean out deprecated APIs
Removes all unstable and deprecated APIs prior to the 1.8 release. All APIs that are deprecated in the 1.8 release are sticking around for the rest of this cycle. Some notable changes are: * The `dynamic_lib` module was moved into `rustc_back` as the compiler still relies on a few bits and pieces. * The `DebugTuple` formatter now special-cases an empty struct name with only one field to append a trailing comma.
Diffstat (limited to 'src/libstd/sys/windows/dynamic_lib.rs')
| -rw-r--r-- | src/libstd/sys/windows/dynamic_lib.rs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/libstd/sys/windows/dynamic_lib.rs b/src/libstd/sys/windows/dynamic_lib.rs new file mode 100644 index 00000000000..84cfbe5e721 --- /dev/null +++ b/src/libstd/sys/windows/dynamic_lib.rs @@ -0,0 +1,55 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use prelude::v1::*; +use os::windows::prelude::*; + +use ffi::{CString, OsStr}; +use io; +use sys::c; + +pub struct DynamicLibrary { + handle: c::HMODULE, +} + +impl DynamicLibrary { + pub fn open(filename: &str) -> io::Result<DynamicLibrary> { + let filename = OsStr::new(filename) + .encode_wide() + .chain(Some(0)) + .collect::<Vec<_>>(); + let result = unsafe { + c::LoadLibraryW(filename.as_ptr()) + }; + if result.is_null() { + Err(io::Error::last_os_error()) + } else { + Ok(DynamicLibrary { handle: result }) + } + } + + pub fn symbol(&self, symbol: &str) -> io::Result<usize> { + let symbol = try!(CString::new(symbol)); + unsafe { + match c::GetProcAddress(self.handle, symbol.as_ptr()) as usize { + 0 => Err(io::Error::last_os_error()), + n => Ok(n), + } + } + } +} + +impl Drop for DynamicLibrary { + fn drop(&mut self) { + unsafe { + c::FreeLibrary(self.handle); + } + } +} |
