Skip to content

Commit

Permalink
strappend doxy: clarification + use case
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPulec committed Oct 26, 2023
1 parent cfa2539 commit f3d7f99
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/utils/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,22 @@ bool ends_with(const char *haystick, const char *needle) {

/**
* Copies string at src to pointer *ptr and increases the pointner.
* Typical use case:
* ````
* consexpr bool nul_terminate = true; // false if not needed
* char buf[STR_LEN];
* char *ptr = buf;
* const char *const end = buf + sizeof buf - null_terminate;
* strappend(&ptr, end, "this");
* strappend(&ptr, end, " and that");
* if (null_terminate) {
* *ptr = '\0';
* }
*
* @todo
* Functions defined in string.h should signal safe in POSIX.1-2008 - check if in glibc, if so, use strcat.
* @note
* Strings are not NULL-terminated.
* Output string is not NULL-terminated but src must be!
*/
void strappend(char **ptr, const char *ptr_end, const char *src) {
while (*src != '\0') {
Expand Down

0 comments on commit f3d7f99

Please sign in to comment.