Files
continuwuity/src/core/mods/new.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

24 lines
653 B
Rust
Raw Normal View History

2024-05-09 15:59:08 -07:00
use std::ffi::OsStr;
use super::{path, Library};
2024-07-28 11:14:10 +00:00
use crate::{Err, Result};
2024-05-09 15:59:08 -07:00
const OPEN_FLAGS: i32 = libloading::os::unix::RTLD_LAZY | libloading::os::unix::RTLD_GLOBAL;
pub fn from_name(name: &str) -> Result<Library> {
let path = path::from_name(name)?;
from_path(&path)
}
pub fn from_path(path: &OsStr) -> Result<Library> {
//SAFETY: Calls dlopen(3) on unix platforms. This might not have to be unsafe
// if wrapped in with_dlerror.
let lib = unsafe { Library::open(Some(path), OPEN_FLAGS) };
if let Err(e) = lib {
let name = path::to_name(path)?;
2024-07-28 11:14:10 +00:00
return Err!("Loading module {name:?} failed: {e}");
2024-05-09 15:59:08 -07:00
}
Ok(lib.expect("module loaded"))
}