Crate sysdir

source ·
Expand description

Enumeration of the filesystem paths for the various standard system directories where apps, resources, etc. get installed.

This crate exposes Rust bindings to the sysdir(3) library functions provided by libSystem.dylib on macOS, iOS, tvOS, and watchOS.

For more detailed documentation, refer to the sysdir(3) man page.

§Platform Support

The sysdir API first appeared in OS X 10.12, iOS 10, watchOS 3 and tvOS 10 replacing the deprecated NSSystemDirectories(3) API.

Note that this crate is completely empty on non-Apple platforms.


sysdir(3) is provided by libSystem, which is linked into every binary on Apple platforms. This crate does not link to CoreFoundation, Foundation, or any other system libraries and frameworks.


use core::ffi::{c_char, CStr};

use sysdir::*;

let mut path = [0; PATH_MAX as usize];

let dir = sysdir_search_path_directory_t::SYSDIR_DIRECTORY_USER;
let domain_mask = SYSDIR_DOMAIN_MASK_LOCAL;

unsafe {
    let mut state = sysdir_start_search_path_enumeration(dir, domain_mask);
    loop {
        let path = path.as_mut_ptr().cast::<c_char>();
        state = sysdir_get_next_search_path_enumeration(state, path);
        if state == 0 {
        let path = CStr::from_ptr(path);
        let s = path.to_str().unwrap();
        assert_eq!(s, "/Users");


  • man page for sysdir(3).





Type Aliases§