~donmcc/astr

A string library for C99.
Change _args suffix to _with_va_list.
Renamed functions with "_format" in their names.
Rename astr_eq_bytes() to astr_eq().

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~donmcc/astr
read/write
git@git.sr.ht:~donmcc/astr

You can also use your local clone with git send-email.

astr

A C99 library for working with dynamically allocated strings.

Overview

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 _from_va_list take variable arguments as a va_list object from stdarg.h.

Functions

char *
astr_alloc_empty(void);

Allocate an empty string.

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

Allocate a formatted string.

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

Allocate a formatted string using a va_list object.

bool
astr_eq(char const *s1, char const *s2);

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

size_t
astr_formatted_length(char const *format, ...);

Calculate the length in bytes needed for the formatted string.

size_t
astr_formatted_length_from_va_list(char const *format, va_list arguments);

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

Dependencies

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

License

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