xref: /plan9/sys/src/cmd/ext2srv/chat.c (revision dc5a79c1208f0704eeb474acc990728f8b4854f5)
1 #include <u.h>
2 #include <libc.h>
3 #include <fcall.h>
4 #include <thread.h>
5 #include <9p.h>
6 #include "dat.h"
7 #include "fns.h"
8 
9 #define	SIZE	1024
10 #define	DOTDOT	(&fmt+1)
11 
12 int	chatty;
13 
14 void
chat(char * fmt,...)15 chat(char *fmt, ...)
16 {
17 	char buf[SIZE], *out;
18 	va_list arg;
19 
20 	if (!chatty)
21 		return;
22 
23 	va_start(arg, fmt);
24 	out = vseprint(buf, buf+sizeof(buf), fmt, arg);
25 	va_end(arg);
26 	write(2, buf, (long)(out-buf));
27 }
28 
29 void
mchat(char * fmt,...)30 mchat(char *fmt, ...)
31 {
32 	char buf[SIZE], *out;
33 	va_list arg;
34 
35 	va_start(arg, fmt);
36 	out = vseprint(buf, buf+sizeof(buf), fmt, arg);
37 	va_end(arg);
38 	write(2, buf, (long)(out-buf));
39 }
40 void
panic(char * fmt,...)41 panic(char *fmt, ...)
42 {
43 	char buf[SIZE];
44 	va_list arg;
45 	int n;
46 
47 	n = sprint(buf, "%s %d: panic ", argv0, getpid());
48 	va_start(arg, fmt);
49 	vseprint(buf+n, buf+sizeof(buf)-n, fmt, arg);
50 	va_end(arg);
51 	fprint(2, "%s: %r\n", buf);
52 	exits("panic");
53 }
54