use std::fs;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::io;
#[inline]
pub fn memchr(needle: u8, haystack: &[u8]) -> Option<usize> {
#[cfg(feature = "memchr")]
return memchr::memchr(needle, haystack);
#[cfg(not(feature = "memchr"))]
{
for (i, &byte) in haystack.iter().enumerate() {
if byte == needle {
return Some(i);
}
}
None
}
}
#[inline]
pub fn nmake(_target: &str) -> Option<Command> {
#[cfg(target_os = "windows")]
return cc::windows_registry::find(_target, "nmake.exe");
#[cfg(not(target_os = "windows"))]
return None;
}
pub fn walk_files<F>(dir: &Path, mut f: F) -> io::Result<()>
where for<'a> F: FnMut(PathBuf) -> io::Result<()>
{
_walk_files(dir, &mut f)
}
fn _walk_files<F>(dir: &Path, f: &mut F) -> io::Result<()>
where for<'a> F: FnMut(PathBuf) -> io::Result<()>
{
for entry in fs::read_dir(dir)? {
let entry = entry?;
let path = entry.path();
if entry.metadata()?.is_dir() {
_walk_files(&path, f)?;
} else {
f(path)?;
}
}
Ok(())
}