mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-07 07:38:59 +00:00
add tools::parse submodule, move hex_nibble to it
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
85a9752ea2
commit
6cf330c9d2
@ -9,6 +9,7 @@ use lazy_static::lazy_static;
|
|||||||
use libc;
|
use libc;
|
||||||
|
|
||||||
use proxmox_tools::fs::file_read_firstline;
|
use proxmox_tools::fs::file_read_firstline;
|
||||||
|
use proxmox_tools::parse::hex_nibble;
|
||||||
|
|
||||||
/// POSIX sysconf call
|
/// POSIX sysconf call
|
||||||
pub fn sysconf(name: i32) -> i64 {
|
pub fn sysconf(name: i32) -> i64 {
|
||||||
@ -325,15 +326,6 @@ pub fn read_proc_net_dev() -> Result<Vec<ProcFsNetDev>, Error> {
|
|||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn hex_nibble(c: u8) -> Result<u8, Error> {
|
|
||||||
Ok(match c {
|
|
||||||
b'0'..=b'9' => c - b'0',
|
|
||||||
b'a'..=b'f' => c - b'a' + 0xa,
|
|
||||||
b'A'..=b'F' => c - b'A' + 0xa,
|
|
||||||
_ => bail!("not a hex digit: {}", c as char),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn hexstr_to_ipv4addr<T: AsRef<[u8]>>(hex: T) -> Result<Ipv4Addr, Error> {
|
fn hexstr_to_ipv4addr<T: AsRef<[u8]>>(hex: T) -> Result<Ipv4Addr, Error> {
|
||||||
let hex = hex.as_ref();
|
let hex = hex.as_ref();
|
||||||
if hex.len() != 8 {
|
if hex.len() != 8 {
|
||||||
|
@ -8,6 +8,7 @@ pub mod common_regex;
|
|||||||
pub mod fd;
|
pub mod fd;
|
||||||
pub mod fs;
|
pub mod fs;
|
||||||
pub mod io;
|
pub mod io;
|
||||||
|
pub mod parse;
|
||||||
pub mod serde;
|
pub mod serde;
|
||||||
pub mod uuid;
|
pub mod uuid;
|
||||||
pub mod vec;
|
pub mod vec;
|
||||||
|
14
proxmox-tools/src/parse.rs
Normal file
14
proxmox-tools/src/parse.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
//! Some parsing utilities.
|
||||||
|
|
||||||
|
use failure::{bail, Error};
|
||||||
|
|
||||||
|
/// Parse a hexadecimal digit into a byte.
|
||||||
|
#[inline]
|
||||||
|
pub fn hex_nibble(c: u8) -> Result<u8, Error> {
|
||||||
|
Ok(match c {
|
||||||
|
b'0'..=b'9' => c - b'0',
|
||||||
|
b'a'..=b'f' => c - b'a' + 0xa,
|
||||||
|
b'A'..=b'F' => c - b'A' + 0xa,
|
||||||
|
_ => bail!("not a hex digit: {}", c as char),
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user