zpmod
b19981f
High-performance Zsh module for script optimization and filesystem helpers
|
Utility helpers shared across module components. More...
Go to the source code of this file.
Functions | |
char * | zp_unmetafy_zalloc (const char *to_copy, int *new_len) |
Duplicate and unmetafy a zsh string using zsh allocators. More... | |
char * | my_ztrdup_glen (const char *s, unsigned *len_ret) |
Duplicate a C string using zalloc and report length. More... | |
int | zp_has_option (char **argv, char opt) |
Lightweight option scanner for argv-style subcommands. More... | |
int | zp_take_opt_with_arg (char ***argvp, char opt, char **out_arg) |
Consume a short option that requires an argument from argv. More... | |
Utility helpers shared across module components.
These helpers follow zpmodās memory rules: allocate with zsh allocators, and free with exact lengths where applicable.
Definition in file zpmod_utils.h.
char* my_ztrdup_glen | ( | const char * | s, |
unsigned * | len_ret | ||
) |
Duplicate a C string using zalloc and report length.
s | Source string (may be NULL). |
len_ret | Out parameter receiving the allocated buffer length. |
*len_ret
), or NULL if s
is NULL.Duplicate a C string using zalloc and report length.
int zp_has_option | ( | char ** | argv, |
char | opt | ||
) |
Lightweight option scanner for argv-style subcommands.
Scans argv
for a short option (e.g., 'l' for -l). Stops at "--" if encountered.
argv | Argument vector terminated by NULL. |
opt | Short option character to detect. |
Lightweight option scanner for argv-style subcommands.
int zp_take_opt_with_arg | ( | char *** | argvp, |
char | opt, | ||
char ** | out_arg | ||
) |
Consume a short option that requires an argument from argv.
Recognizes patterns "-oARG" (attached) and "-o ARG" (separate). When matched, advances the argv pointer and writes the argument to out_arg.
argvp | In/out pointer to argv cursor (modified on consumption). |
opt | Short option character to match (e.g., 'd'). |
out_arg | Out parameter set to the option argument on success. |
Consume a short option that requires an argument from argv.
Supports both attached (-oARG) and separate (-o ARG) forms.
Definition at line 35 of file utils.c.
Referenced by cmd_pathstat().
char* zp_unmetafy_zalloc | ( | const char * | to_copy, |
int * | new_len | ||
) |
Duplicate and unmetafy a zsh string using zsh allocators.
Makes a new allocation with zalloc, containing the unmetafied copy of to_copy
. When new_len
is provided, it receives the exact buffer length to use with zfree.
to_copy | Metafied zsh string to duplicate and unmetafy. |
new_len | Optional out parameter for the returned buffer length. |
Duplicate and unmetafy a zsh string using zsh allocators.