summaryrefslogtreecommitdiff
path: root/src/librandom/random_sauniquename_from.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2022-04-09 02:28:05 +0000
committerLaurent Bercot <ska@appnovation.com>2022-04-09 02:28:05 +0000
commit4e75b40d8a96c5d51490ddea43566fe8e6d4168c (patch)
tree06358f285c713a7f05297cb7d2826319d6561683 /src/librandom/random_sauniquename_from.c
parent1fedaae65b56b8548cdf2d8c26e2becece5fec07 (diff)
downloadskalibs-4e75b40d8a96c5d51490ddea43566fe8e6d4168c.tar.xz
Prepare for 2.12.0.0. librandom revamp.
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/librandom/random_sauniquename_from.c')
-rw-r--r--src/librandom/random_sauniquename_from.c21
1 files changed, 21 insertions, 0 deletions
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 <skalibs/stralloc.h>
+#include <skalibs/skamisc.h>
+#include <skalibs/random.h>
+
+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 ;
+}