1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
- #include "acd.h"
- void*
- emalloc(uint n)
- {
- void *p;
- p = malloc(n);
- if(p == nil)
- error("can't malloc: %r");
- memset(p, 0, n);
- return p;
- }
- char*
- estrdup(char *s)
- {
- char *t;
- t = emalloc(strlen(s)+1);
- strcpy(t, s);
- return t;
- }
- char*
- estrstrdup(char *s, char *t)
- {
- char *u;
- u = emalloc(strlen(s)+strlen(t)+1);
- strcpy(u, s);
- strcat(u, t);
- return u;
- }
- char*
- eappend(char *s, char *sep, char *t)
- {
- char *u;
- if(t == nil)
- u = estrstrdup(s, sep);
- else{
- u = emalloc(strlen(s)+strlen(sep)+strlen(t)+1);
- strcpy(u, s);
- strcat(u, sep);
- strcat(u, t);
- }
- free(s);
- return u;
- }
- char*
- egrow(char *s, char *sep, char *t)
- {
- s = eappend(s, sep, t);
- free(t);
- return s;
- }
- void
- error(char *fmt, ...)
- {
- int n;
- va_list arg;
- char buf[256];
- fprint(2, "Mail: ");
- va_start(arg, fmt);
- n = vsnprint(buf, sizeof buf, fmt, arg);
- va_end(arg);
- write(2, buf, n);
- write(2, "\n", 1);
- threadexitsall(fmt);
- }
- void
- ctlprint(int fd, char *fmt, ...)
- {
- int n;
- va_list arg;
- char buf[256];
- va_start(arg, fmt);
- n = vsnprint(buf, sizeof buf, fmt, arg);
- va_end(arg);
- if(write(fd, buf, n) != n)
- error("control file write error: %r");
- }
|