Skip to main content

libblkid_rs/
version.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5use std::{
6    ffi::{CStr, CString},
7    ptr,
8};
9
10use libc::{c_char, c_int};
11
12use crate::Result;
13
14/// Parse a version string into a version code
15pub fn parse_version_string(version_str: &str) -> Result<c_int> {
16    let version_cstring = CString::new(version_str)?;
17    Ok(unsafe { libblkid_rs_sys::blkid_parse_version_string(version_cstring.as_ptr()) })
18}
19
20/// Get library version
21pub fn get_library_version() -> Result<(c_int, String, String)> {
22    let mut ver_ptr: *const c_char = ptr::null();
23    let mut date_ptr: *const c_char = ptr::null();
24    let ver_code = unsafe {
25        libblkid_rs_sys::blkid_get_library_version(
26            &mut ver_ptr as *mut *const _,
27            &mut date_ptr as *mut *const _,
28        )
29    };
30    let ver_string = unsafe { CStr::from_ptr(ver_ptr) }.to_str()?.to_string();
31    let date_string = unsafe { CStr::from_ptr(date_ptr) }.to_str()?.to_string();
32    Ok((ver_code, ver_string, date_string))
33}