From 4e75b40d8a96c5d51490ddea43566fe8e6d4168c Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 9 Apr 2022 02:28:05 +0000 Subject: Prepare for 2.12.0.0. librandom revamp. Signed-off-by: Laurent Bercot --- src/librandom/random_sauniquename_from.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/librandom/random_sauniquename_from.c (limited to 'src/librandom/random_sauniquename_from.c') diff --git a/src/librandom/random_sauniquename_from.c b/src/librandom/random_sauniquename_from.c new file mode 100644 index 0000000..132d303 --- /dev/null +++ b/src/librandom/random_sauniquename_from.c @@ -0,0 +1,21 @@ +/* ISC license. */ + +#include +#include +#include + +int random_sauniquename_from (stralloc *sa, size_t n, randomgen_func_ref f) +{ + size_t base = sa->len ; + int wasnull = !sa->s ; + if (!sauniquename(sa)) return 0 ; + if (!stralloc_readyplus(sa, n+1)) goto err ; + stralloc_catb(sa, ":", 1) ; + random_name_from(sa->s + sa->len, n, f) ; + sa->len += n ; + return 1 ; + +err: + if (wasnull) stralloc_free(sa) ; else sa->len = base ; + return 0 ; +} -- cgit v1.2.3