zlob 1.5.0-dev.3

SIMD optimized glob pattern matching library faster than glob crate
Documentation
// Stub FFI bindings for docs.rs builds where bindgen cannot run.
// This file provides the minimal type definitions needed for documentation
// generation without the actual native library.

use core::ffi::{c_char, c_int, c_uchar};

pub const ZLOB_ERR: c_int = 1 << 0;
pub const ZLOB_MARK: c_int = 1 << 1;
pub const ZLOB_NOSORT: c_int = 1 << 2;
pub const ZLOB_DOOFFS: c_int = 1 << 3;
pub const ZLOB_NOCHECK: c_int = 1 << 4;
pub const ZLOB_APPEND: c_int = 1 << 5;
pub const ZLOB_NOESCAPE: c_int = 1 << 6;
pub const ZLOB_PERIOD: c_int = 1 << 7;
pub const ZLOB_MAGCHAR: c_int = 1 << 8;
pub const ZLOB_ALTDIRFUNC: c_int = 1 << 9;
pub const ZLOB_BRACE: c_int = 1 << 10;
pub const ZLOB_NOMAGIC: c_int = 1 << 11;
pub const ZLOB_TILDE: c_int = 1 << 12;
pub const ZLOB_ONLYDIR: c_int = 1 << 13;
pub const ZLOB_TILDE_CHECK: c_int = 1 << 14;
pub const ZLOB_GITIGNORE: c_int = 1 << 24;
pub const ZLOB_DOUBLESTAR_RECURSIVE: c_int = 1 << 25;
pub const ZLOB_EXTGLOB: c_int = 1 << 26;
pub const ZLOB_FOLLOW_SYMLINKS: c_int = 1 << 27;

pub const ZLOB_RECOMMENDED: c_int =
    ZLOB_BRACE | ZLOB_DOUBLESTAR_RECURSIVE | ZLOB_NOSORT | ZLOB_TILDE | ZLOB_TILDE_CHECK;

pub const ZLOB_NOSPACE: c_int = 1;
pub const ZLOB_ABORTED: c_int = 2;
pub const ZLOB_NOMATCH: c_int = 3;
pub const ZLOB_READ_FAILED: c_int = 4;
pub const ZLOB_PERMISSION_DENIED: c_int = 5;
pub const ZLOB_NAME_TOO_LONG: c_int = 6;

pub const ZLOB_DT_UNKNOWN: c_uchar = 0;
pub const ZLOB_DT_DIR: c_uchar = 4;
pub const ZLOB_DT_REG: c_uchar = 8;
pub const ZLOB_DT_LNK: c_uchar = 10;

#[repr(C)]
pub struct zlob_dirent_t {
    pub d_name: *const c_char,
    pub d_type: c_uchar,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub struct zlob_slice_t {
    pub ptr: *const c_uchar,
    pub len: usize,
}

#[repr(C)]
pub struct zlob_t {
    pub zlo_pathc: usize,
    pub zlo_pathv: *mut *mut c_char,
    pub zlo_offs: usize,
    pub zlo_pathlen: *mut usize,
    pub zlo_flags: c_int,
    pub zlo_opendir: Option<unsafe extern "C" fn(path: *const c_char) -> *mut core::ffi::c_void>,
    pub zlo_readdir:
        Option<unsafe extern "C" fn(dir: *mut core::ffi::c_void) -> *mut zlob_dirent_t>,
    pub zlo_closedir: Option<unsafe extern "C" fn(dir: *mut core::ffi::c_void)>,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct zlob_indices_t {
    pub indices: *mut usize,
    pub count: usize,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct zlob_pattern {
    _unused: [u8; 0],
}

pub type zlob_pattern_t = zlob_pattern;

// Stub functions - these will never be called during doc builds
unsafe extern "C" {
    pub fn zlob(
        pattern: *const c_char,
        flags: c_int,
        errfunc: Option<unsafe extern "C" fn(epath: *const c_char, eerrno: c_int) -> c_int>,
        pzlob: *mut zlob_t,
    ) -> c_int;

    pub fn zlobfree(pzlob: *mut zlob_t);

    pub fn zlob_at(
        base_path: *const c_char,
        pattern: *const c_char,
        flags: c_int,
        errfunc: Option<unsafe extern "C" fn(epath: *const c_char, eerrno: c_int) -> c_int>,
        pzlob: *mut zlob_t,
    ) -> c_int;

    pub fn zlob_match_paths_slice(
        pattern: *const zlob_slice_t,
        paths: *const zlob_slice_t,
        path_count: usize,
        flags: c_int,
        pzlob: *mut zlob_t,
    ) -> c_int;

    pub fn zlob_match_paths(
        pattern: *const c_char,
        paths: *const *const c_char,
        path_count: usize,
        flags: c_int,
        pzlob: *mut zlob_t,
    ) -> c_int;

    pub fn zlob_match_paths_at(
        base_path: *const c_char,
        pattern: *const c_char,
        paths: *const *const c_char,
        path_count: usize,
        flags: c_int,
        pzlob: *mut zlob_t,
    ) -> c_int;

    pub fn zlob_match_paths_at_slice(
        base_path: *const zlob_slice_t,
        pattern: *const zlob_slice_t,
        paths: *const zlob_slice_t,
        path_count: usize,
        flags: c_int,
        pzlob: *mut zlob_t,
    ) -> c_int;

    pub fn zlob_has_wildcards(pattern: *const c_char, flags: c_int) -> c_int;

    pub fn zlob_indices_free(out: *mut zlob_indices_t);

    pub fn zlob_pattern_compile(pattern: *const c_char, flags: c_int) -> *mut zlob_pattern_t;

    pub fn zlob_pattern_compile_slice(
        pattern: *const zlob_slice_t,
        flags: c_int,
    ) -> *mut zlob_pattern_t;

    pub fn zlob_pattern_free(p: *mut zlob_pattern_t);

    pub fn zlob_pattern_matches(
        p: *const zlob_pattern_t,
        path: *const c_char,
        path_len: usize,
        flags: c_int,
    ) -> c_int;

    pub fn zlob_match_paths_indices(
        pattern: *const c_char,
        paths: *const *const c_char,
        path_count: usize,
        flags: c_int,
        out: *mut zlob_indices_t,
    ) -> c_int;

    pub fn zlob_match_paths_indices_slice(
        pattern: *const zlob_slice_t,
        paths: *const zlob_slice_t,
        path_count: usize,
        flags: c_int,
        out: *mut zlob_indices_t,
    ) -> c_int;

    pub fn zlob_match_paths_indices_at(
        base_path: *const c_char,
        pattern: *const c_char,
        paths: *const *const c_char,
        path_count: usize,
        flags: c_int,
        out: *mut zlob_indices_t,
    ) -> c_int;

    pub fn zlob_match_paths_indices_at_slice(
        base_path: *const zlob_slice_t,
        pattern: *const zlob_slice_t,
        paths: *const zlob_slice_t,
        path_count: usize,
        flags: c_int,
        out: *mut zlob_indices_t,
    ) -> c_int;

    pub fn zlob_pattern_match_paths_slice(
        p: *const zlob_pattern_t,
        paths: *const zlob_slice_t,
        path_count: usize,
        flags: c_int,
        out: *mut zlob_t,
    ) -> c_int;

    pub fn zlob_pattern_match_paths_at_slice(
        p: *const zlob_pattern_t,
        base_path: *const zlob_slice_t,
        paths: *const zlob_slice_t,
        path_count: usize,
        flags: c_int,
        out: *mut zlob_t,
    ) -> c_int;

    pub fn zlob_pattern_match_paths_indices_slice(
        p: *const zlob_pattern_t,
        paths: *const zlob_slice_t,
        path_count: usize,
        flags: c_int,
        out: *mut zlob_indices_t,
    ) -> c_int;

    pub fn zlob_pattern_match_paths_indices_at_slice(
        p: *const zlob_pattern_t,
        base_path: *const zlob_slice_t,
        paths: *const zlob_slice_t,
        path_count: usize,
        flags: c_int,
        out: *mut zlob_indices_t,
    ) -> c_int;
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct zlob_walk_options_t {
    pub flags: u32,
    pub meta_mask: u32,
    pub threads: u16,
    pub max_depth: u16,
    pub errfunc: Option<unsafe extern "C" fn(epath: *const c_char, eerrno: c_int) -> c_int>,
    pub pattern: *const c_char,
    pub pattern_flags: u32,
    /// Caller-supplied .gitignore document, one rule per line, NUL-terminated.
    /// Null = none. Layered as the *deepest* node in the ignore chain so its
    /// `!negation` rules override the project's `.gitignore`.
    pub extra_ignore: *const c_char,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct zlob_walk_entry_t {
    pub path: *const c_char,
    pub path_len: usize,
    pub relative_offset: u32,
    pub basename_offset: u32,
    pub kind: u8,
    pub depth: u16,
    pub meta_valid: u32,
    pub size: u64,
    pub mtime_ns: i64,
    pub atime_ns: i64,
    pub ctime_ns: i64,
    pub btime_ns: i64,
    pub inode: u64,
    pub nlink: u32,
    pub mode: u32,
    pub uid: u32,
    pub gid: u32,
}

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct zlob_walk_result_t {
    pub entries: *mut zlob_walk_entry_t,
    pub count: usize,
    pub _storage: *mut core::ffi::c_void,
}

pub type zlob_walk_cb = Option<
    unsafe extern "C" fn(entry: *const zlob_walk_entry_t, ctx: *mut core::ffi::c_void) -> c_int,
>;

unsafe extern "C" {
    pub fn zlob_walk(
        root: *const c_char,
        options: *const zlob_walk_options_t,
        cb: zlob_walk_cb,
        ctx: *mut core::ffi::c_void,
        out_rules: *mut *mut core::ffi::c_void,
    ) -> c_int;

    pub fn zlob_ignore_rules_free(rules: *mut core::ffi::c_void);

    pub fn zlob_walk_collect(
        root: *const c_char,
        options: *const zlob_walk_options_t,
        out: *mut zlob_walk_result_t,
    ) -> c_int;

    pub fn zlob_walk_result_free(result: *mut zlob_walk_result_t);

    pub fn zlob_walk_result_ignore_rules(
        result: *const zlob_walk_result_t,
    ) -> *mut core::ffi::c_void;

    pub fn zlob_ignore_rules_match_path(
        rules: *mut core::ffi::c_void,
        path: *const c_char,
    ) -> c_int;
}