12 void NORETURN_ATTR
GCC_FMT_ATTR (2, 3) err (int exitcode
, const char *fmt
, ...)
19 vfprintf (stderr
, fmt
, ap
);
21 fprintf (stderr
, ": %s\n", strerror (savederrno
));
26 void NORETURN_ATTR
GCC_FMT_ATTR (2, 3) errx (int exitcode
, const char *fmt
, ...)
31 vfprintf (stderr
, fmt
, ap
);
38 void *parse_pointer (const char *cap
, const char *s
)
43 ret
= sscanf (s
, "%" SCNxPTR
, (uintptr_t *) &ptr
);
45 errx (1, "%s: cannot parse pointer in `%s'", cap
, s
);
53 gettimeofday (&tv
, NULL
);
54 return tv
.tv_sec
+ tv
.tv_usec
*1e-6;
57 /* slightly tweaked fmt_ulong by D.J. Bernstein */
58 void fmt_linkn (char *s
, unsigned int u
)
60 unsigned int len
; unsigned int q
;
61 unsigned int zma
= 'z' - 'a' + 1;
63 while (q
> zma
- 1) { ++len
; q
/= zma
; }
66 do { *--s
= (char)('a' + (u
% zma
) - (u
< zma
&& len
> 1));
73 char *ystrdup (const char *s
)
75 size_t len
= strlen (s
);
77 char *r
= malloc (len
+1);
78 if (!r
) errx (1, "malloc %zu", len
+1);