1#include <alloc.h>
2#include <byte.h>
3#include <fmt.h>
4#include <str.h>
5#include <strerr.h>
6
7#include "util.h"
8
9extern const char *argv0;
10
11char *
12copystr(const char *s)
13{
14 unsigned int n;
15 char *out;
16
17 n = str_len(s) + 1;
18 out = alloc(n);
19 if (!out)
20 die_nomem();
21 byte_copy(out, n, (char *)s);
22 return out;
23}
24
25void
26die_nomem(void)
27{
28 strerr_die2sys(111, argv0, ": alloc");
29}
30
31void
32put_ulong(buffer *b, unsigned long u)
33{
34 char buf[FMT_ULONG];
35 unsigned int len;
36
37 len = fmt_ulong(buf, u);
38 buffer_put(b, buf, len);
39}