use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;
use crate::search_path::*;
pub fn parse_ld_so_conf<P: AsRef<Path>>(filename: &P) -> Result<SearchPathVec, &'static str> {
let mut lines = match read_lines(filename) {
Ok(lines) => lines,
Err(_e) => return Err("Could not open the filename"),
};
let mut r = SearchPathVec::new();
while let Some(Ok(line)) = lines.next() {
let line = match parse_line(&line) {
Some(line) => line,
None => continue,
};
r.add_path(&line);
}
Ok(r)
}
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
where
P: AsRef<Path>,
{
let file = File::open(filename)?;
Ok(io::BufReader::new(file).lines())
}
fn parse_line(line: &str) -> Option<String> {
let line = line.trim_start();
let comment = match line.find('#') {
Some(comment) => comment,
None => line.len(),
};
let line = &line[0..comment];
let line = line.trim_end();
if line.is_empty() {
return None;
}
Some(line.to_string())
}