-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from mulimoen/fix-capath
Allow user to set CAPATH/CAINFO
- Loading branch information
Showing
8 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "netcdf-src/source"] | ||
path = netcdf-src/source | ||
url = https://github.com/gigainfosystems/netcdf-c | ||
url = https://github.com/mulimoen/netcdf-c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::ffi::{c_char, CStr, CString}; | ||
use std::ops::Deref; | ||
use std::ptr::NonNull; | ||
|
||
pub fn set(key: &str, value: &str) -> crate::error::Result<()> { | ||
let key = CString::new(key)?; | ||
let value = CString::new(value)?; | ||
crate::error::checked(crate::with_lock(|| unsafe { | ||
netcdf_sys::nc_rc_set(key.as_ptr(), value.as_ptr()) | ||
})) | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct OwnedString { | ||
inner: NonNull<c_char>, | ||
} | ||
|
||
impl Deref for OwnedString { | ||
type Target = CStr; | ||
fn deref(&self) -> &Self::Target { | ||
unsafe { CStr::from_ptr(self.inner.as_ptr()) } | ||
} | ||
} | ||
|
||
impl Drop for OwnedString { | ||
fn drop(&mut self) { | ||
unsafe { | ||
libc::free(self.inner.as_ptr().cast()); | ||
} | ||
} | ||
} | ||
|
||
pub fn get(key: &str) -> Option<OwnedString> { | ||
let key = if let Ok(key) = CString::new(key) { | ||
key | ||
} else { | ||
return None; | ||
}; | ||
let _lock = netcdf_sys::libnetcdf_lock.lock().unwrap(); | ||
let value = unsafe { netcdf_sys::nc_rc_get(key.as_ptr()) }; | ||
NonNull::new(value).map(|inner| OwnedString { inner }) | ||
} |