cat-dev 0.0.14

A library for interacting with the CAT-DEV hardware units distributed by Nintendo (i.e. a type of Wii-U DevKits).
Documentation
//! Utility functions that are used within various parts of the host filesystem.

use std::{
	path::{Path, PathBuf},
	sync::atomic::{AtomicI32, Ordering},
};

/// A way to create truly unique file fd's. Just a counter going up.
static UNIQUE_FILE_FD: AtomicI32 = AtomicI32::new(1);
/// Current "FD" for directories. Just a counter going up.
static FOLDER_FD: AtomicI32 = AtomicI32::new(1);

/// Get a new unique file descriptor for a file.
#[allow(clippy::inline_always)]
#[inline(always)]
#[must_use]
pub fn get_new_unique_file_fd() -> i32 {
	UNIQUE_FILE_FD.fetch_add(1, Ordering::SeqCst)
}
/// Get a new unique file descriptor for a folder.
#[allow(clippy::inline_always)]
#[inline(always)]
#[must_use]
pub fn get_new_unique_folder_fd() -> i32 {
	FOLDER_FD.fetch_add(1, Ordering::SeqCst)
}

/// A small utility function to join many paths into a single path effeciently.
#[must_use]
pub fn join_many<PathTy, IterTy>(base: &Path, parts: IterTy) -> PathBuf
where
	PathTy: AsRef<Path>,
	IterTy: IntoIterator<Item = PathTy>,
{
	let mut as_owned = PathBuf::from(base);
	for part in parts {
		as_owned = as_owned.join(part.as_ref());
	}
	as_owned
}