zpmod
b19981f
High-performance Zsh module for script optimization and filesystem helpers
|
Core filesystem routines used by builtins and subcommands. More...
#include "zpmod.mdh"
#include "zpmod.pro"
#include "zpmod_vendor_shims.h"
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "zpmod_fs.h"
Go to the source code of this file.
Data Structures | |
struct | zp_fs_cache_entry |
Macros | |
#define | GET_ZPMOD_CONFIG(K) getsparam("ZPMOD_" #K) |
#define | ZP_FS_CACHE_MAX 64 |
Functions | |
int | zp_pathstat_core (char *nam, char *outname, char *inname, int follow, char *fields) |
See zpmod_fs.h for contract. More... | |
static int | zp_fs_cache_enabled (void) |
static int | zp_fs_cache_lookup (const char *dir, struct stat *st, int *out_idx) |
static int | zp_fs_cache_insert_dir (const char *dir, const struct stat *st, char *serialized) |
int | zp_path_warmup_core (const char *nam, int quiet, int prune_missing, int dry_run) |
Implements path-warmup functionality for executable discovery and path pruning. More... | |
int | zp_dirlist_core (char *nam, char *outname, char *dir, int inc_all, int only_dirs, int only_files) |
See zpmod_fs.h for contract. More... | |
int | zp_readfile_core (char *nam, char *outname, char *path, int use_mmap, int split, int delim) |
See zpmod_fs.h for contract. More... | |
Variables | |
static zp_fs_cache_entry | zp_fs_cache [ZP_FS_CACHE_MAX] |
static int | zp_fs_cache_count = 0 |
Core filesystem routines used by builtins and subcommands.
Definition in file fs.c.
int zp_dirlist_core | ( | char * | nam, |
char * | outname, | ||
char * | dir, | ||
int | inc_all, | ||
int | only_dirs, | ||
int | only_files | ||
) |
See zpmod_fs.h for contract.
List directory entries into an output array with filters.
Definition at line 382 of file fs.c.
References metafy(), PATH_MAX, setaparam(), setsparam(), unsetparam(), zalloc(), zfree(), zp_unmetafy_zalloc(), and zwarnnam().
Referenced by bin_zpdirlist(), and cmd_dirlist().
|
static |
Definition at line 144 of file fs.c.
References GET_ZPMOD_CONFIG.
|
static |
Definition at line 178 of file fs.c.
References zp_fs_cache_entry::dev, zp_fs_cache_entry::dir_entries, zp_fs_cache_entry::ino, zp_fs_cache_entry::is_dir, zp_fs_cache_entry::mtime, zp_fs_cache_entry::size, zp_fs_cache, zp_fs_cache_count, ZP_FS_CACHE_MAX, and zsfree().
|
static |
Definition at line 162 of file fs.c.
References zp_fs_cache_entry::dev, zp_fs_cache_entry::ino, zp_fs_cache_entry::is_dir, zp_fs_cache_entry::mtime, zp_fs_cache_entry::size, zp_fs_cache, and zp_fs_cache_count.
int zp_path_warmup_core | ( | const char * | nam, |
int | quiet, | ||
int | prune_missing, | ||
int | dry_run | ||
) |
Implements path-warmup functionality for executable discovery and path pruning.
Scan $PATH directories to warm filesystem caches and prepare command lookup.
This function provides two main features:
The prune functionality was redesigned to avoid memory corruption issues that occurred when mixing getaparam("path")
results with setaparam("path")
calls. The original implementation caused double-free errors due to zsh's parameter management internals.
Solution: Use a two-pass approach with separate array construction:
ztrdup()
for proper string ownershipsetaparam("path", new_array)
without dependency on getaparam()
resultnam | Builtin name for error reporting |
quiet | Suppress progress messages if true |
prune_missing | Remove non-existent directories from path if true |
dry_run | Report what would be pruned without making changes if true |
Definition at line 254 of file fs.c.
References arrlen(), getaparam(), PATH_MAX, setaparam(), zalloc(), and ztrdup().
Referenced by bin_zpmod().
int zp_pathstat_core | ( | char * | nam, |
char * | outname, | ||
char * | inname, | ||
int | follow, | ||
char * | fields | ||
) |
See zpmod_fs.h for contract.
Batch stat entries from an input array into an output array.
Definition at line 36 of file fs.c.
References getaparam(), metafy(), setaparam(), setsparam(), unsetparam(), zalloc(), zfree(), zp_unmetafy_zalloc(), and zwarnnam().
Referenced by bin_zppathstat(), and cmd_pathstat().
int zp_readfile_core | ( | char * | nam, |
char * | outname, | ||
char * | path, | ||
int | use_mmap, | ||
int | split, | ||
int | delim | ||
) |
See zpmod_fs.h for contract.
Read a file into a scalar or split into an array by delimiter.
Definition at line 444 of file fs.c.
References metafy(), path, setaparam(), setsparam(), unsetparam(), zalloc(), zfree(), zp_unmetafy_zalloc(), zrealloc(), and zwarnnam().
Referenced by bin_zpreadfile(), and cmd_readfile().
|
static |
Definition at line 159 of file fs.c.
Referenced by zp_fs_cache_insert_dir(), and zp_fs_cache_lookup().
|
static |
Definition at line 160 of file fs.c.
Referenced by zp_fs_cache_insert_dir(), and zp_fs_cache_lookup().