1 /* Written by Kris Maglione <fbsdaemon at gmail dot com> */
12 fatal(const char *fmt
, ...) {
17 fprintf(stderr
, "%s: fatal: ", argv0
);
20 vfprintf(stderr
, fmt
, ap
);
23 if(fmt
[strlen(fmt
)-1] == ':')
24 fprintf(stderr
, " %s\n", strerror(err
));
26 fprintf(stderr
, "\n");
33 mfatal(char *name
, unsigned int size
) {
35 couldnot
[] = ": fatal: Could not ",
43 sizestr
[--i
] = '0' + (size
%10);
47 write(1, argv0
, strlen(argv0
)-1);
48 write(1, couldnot
, sizeof(couldnot
)-1);
49 write(1, name
, strlen(name
));
50 write(1, paren
, sizeof(paren
)-1);
51 write(1, sizestr
+i
, sizeof(sizestr
)-i
);
52 write(1, bytes
, sizeof(bytes
)-1);
58 emalloc(unsigned int size
) {
59 void *ret
= malloc(size
);
61 mfatal("malloc", size
);
66 emallocz(unsigned int size
) {
67 void *ret
= emalloc(size
);
73 erealloc(void *ptr
, unsigned int size
) {
74 void *ret
= realloc(ptr
, size
);
76 mfatal("realloc", size
);
81 estrdup(const char *str
) {
82 void *ret
= strdup(str
);
84 mfatal("strdup", strlen(str
));
89 tokenize(char *res
[], unsigned int reslen
, char *str
, char delim
) {
95 while(i
< reslen
&& *s
) {
100 while(*s
&& *s
!= delim
)
121 strlcat(char *dst
, const char *src
, unsigned int size
) {
129 while(n
-- > 0 && *d
!= '\0')