zpmod  b19981f
High-performance Zsh module for script optimization and filesystem helpers
utils.c File Reference

Utility functions for argument parsing and string handling. More...

#include "zpmod.mdh"
#include "zpmod.pro"
#include "zpmod_utils.h"
#include "zpmod_vendor_shims.h"
#include <string.h>
Include dependency graph for utils.c:

Go to the source code of this file.

Functions

int zp_has_option (char **argv, char opt)
 Lightweight argv short-option scanner (stops at "--"). More...
 
int zp_take_opt_with_arg (char ***argvp, char opt, char **out_arg)
 Consume a short option with required argument from argv. More...
 
char * my_ztrdup_glen (const char *s, unsigned *len_ret)
 zalloc-backed strdup with length out parameter. More...
 
char * zp_unmetafy_zalloc (const char *to_copy, int *new_len)
 Duplicate and unmetafy a zsh string with zalloc; see header for details. More...
 

Detailed Description

Utility functions for argument parsing and string handling.

Definition in file utils.c.

Function Documentation

◆ my_ztrdup_glen()

char* my_ztrdup_glen ( const char *  s,
unsigned *  len_ret 
)

zalloc-backed strdup with length out parameter.

Duplicate a C string using zalloc and report length.

Definition at line 63 of file utils.c.

References zalloc().

Referenced by zp_unmetafy_zalloc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ zp_has_option()

int zp_has_option ( char **  argv,
char  opt 
)

Lightweight argv short-option scanner (stops at "--").

Lightweight option scanner for argv-style subcommands.

Definition at line 13 of file utils.c.

◆ zp_take_opt_with_arg()

int zp_take_opt_with_arg ( char ***  argvp,
char  opt,
char **  out_arg 
)

Consume a short option with required argument from argv.

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().

Here is the caller graph for this function:

◆ zp_unmetafy_zalloc()

char * zp_unmetafy_zalloc ( const char *  to_copy,
int *  new_len 
)

Duplicate and unmetafy a zsh string with zalloc; see header for details.

Duplicate and unmetafy a zsh string using zsh allocators.

Definition at line 76 of file utils.c.

References my_ztrdup_glen(), unmetafy(), zalloc(), and zfree().

Referenced by cmd_report_append(), zp_dirlist_core(), zp_pathstat_core(), and zp_readfile_core().

Here is the call graph for this function:
Here is the caller graph for this function: