blob: ddf47ec63953aae1226eb78672dc70c16e0e0c24 (
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
26
27
28
|
/* ISC license. */
#include <unistd.h>
#include <skalibs/djbunix.h>
#include <skalibs/skamisc.h>
#include <skalibs/stralloc.h>
#include <skalibs/tai.h>
#include <skalibs/uint.h>
int sauniquename (stralloc *sa)
{
unsigned int base = sa->len ;
int wasnull = !sa->s ;
if (!stralloc_readyplus(sa, TIMESTAMP + UINT_FMT + 131)) return 0 ;
sa->s[base] = ':' ;
timestamp(sa->s + base + 1) ;
sa->s[base + 1 + TIMESTAMP] = ':' ;
sa->len = base + 2 + TIMESTAMP ;
sa->len += uint_fmt(sa->s + sa->len, getpid()) ;
sa->s[sa->len++] = ':' ;
if (sagethostname(sa) == -1) goto err ;
return 1 ;
err:
if (wasnull) stralloc_free(sa) ; else sa->len = base ;
return 0 ;
}
|