blob: 7c902ef82ba5109adc395940ee87c0612da1cdce (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
/* ISC license. */
/* MT-unsafe */
#include <skalibs/stralloc.h>
#include <skalibs/skamisc.h>
#include <skalibs/random.h>
int random_sauniquename (stralloc *sa, unsigned int n)
{
unsigned int base = sa->len ;
int wasnull = !sa->s ;
register int r ;
if (sauniquename(sa) == -1) return -1 ;
if (!stralloc_readyplus(sa, n+1)) goto err ;
stralloc_catb(sa, ":", 1) ;
r = random_name(sa->s + sa->len, n) ;
if (r == -1) goto err ;
sa->len += r ;
return r ;
err:
if (wasnull) stralloc_free(sa) ; else sa->len = base ;
return -1 ;
}
|