chat.c 827 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #define SIZE 1024
  9. #define DOTDOT (&fmt+1)
  10. int chatty;
  11. void
  12. chat(char *fmt, ...)
  13. {
  14. char buf[SIZE], *out;
  15. va_list arg;
  16. if (!chatty)
  17. return;
  18. va_start(arg, fmt);
  19. out = vseprint(buf, buf+sizeof(buf), fmt, arg);
  20. va_end(arg);
  21. write(2, buf, (long)(out-buf));
  22. }
  23. void
  24. mchat(char *fmt, ...)
  25. {
  26. char buf[SIZE], *out;
  27. va_list arg;
  28. va_start(arg, fmt);
  29. out = vseprint(buf, buf+sizeof(buf), fmt, arg);
  30. va_end(arg);
  31. write(2, buf, (long)(out-buf));
  32. }
  33. void
  34. panic(char *fmt, ...)
  35. {
  36. char buf[SIZE];
  37. va_list arg;
  38. int n;
  39. n = sprint(buf, "%s %d: panic ", argv0, getpid());
  40. va_start(arg, fmt);
  41. vseprint(buf+n, buf+sizeof(buf)-n, fmt, arg);
  42. va_end(arg);
  43. fprint(2, "%s: %r\n", buf);
  44. exits("panic");
  45. }