ref: 8f2fd999ba6bf5d5dd8abc905cc12cf5838d2409 astr/README.md -rw-r--r-- 2.1 KiB
8f2fd999Don McCaughey Replace ternary expression with if statement. 2 years ago


A C99 library for working with dynamically allocated strings.

builds.sr.ht status


All functions in astr begin with the astr_ prefix. Functions that return newly allocated strings will contain _alloc in their names; the caller is responsible for calling free() on the returned pointer. Functions with _format take a printf() style format string. Functions that end with the suffix _args take variable arguments as a va_list object from stdarg.h.


char *

Allocate an empty string.

char *
astr_alloc_format(char const *format, ...);

Allocate a formatted string.

char *
astr_alloc_format_args(char const *format, va_list arguments);

Allocate a formatted string using a va_list object.

astr_eq_bytes(char const *s1, char const *s2);

Compare the bytes of two strings for equality; s1 and s2 may be NULL.

astr_len_format(char const *format, ...);

Calculate the length in bytes needed for the formatted string.

astr_len_format_args(char const *format, va_list arguments);

Calculate the length in bytes needed for the formatted string using a va_list object.


astr requires that <stdio.h> defines the vasprintf() and vsnprintf() functions. Building from repository source requires GNU Autotools.

#Building from Repository Source

Clone the repository then generate the configure script, configure and build.

git clone https://git.sr.ht/~donmcc/astr
cd astr
autoreconf -i
mkdir tmp && cd tmp
../configure && make && sudo make install


astr is made available under a BSD-style license; see the LICENSE file for details.