chat.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <fcall.h>
  12. #include <thread.h>
  13. #include <9p.h>
  14. #include "dat.h"
  15. #include "fns.h"
  16. #define SIZE 1024
  17. #define DOTDOT (&fmt+1)
  18. int chatty;
  19. void
  20. chat(char *fmt, ...)
  21. {
  22. char buf[SIZE], *out;
  23. va_list arg;
  24. if (!chatty)
  25. return;
  26. va_start(arg, fmt);
  27. out = vseprint(buf, buf+sizeof(buf), fmt, arg);
  28. va_end(arg);
  29. write(2, buf, (int32_t)(out-buf));
  30. }
  31. void
  32. mchat(char *fmt, ...)
  33. {
  34. char buf[SIZE], *out;
  35. va_list arg;
  36. va_start(arg, fmt);
  37. out = vseprint(buf, buf+sizeof(buf), fmt, arg);
  38. va_end(arg);
  39. write(2, buf, (int32_t)(out-buf));
  40. }
  41. void
  42. panic(char *fmt, ...)
  43. {
  44. char buf[SIZE];
  45. va_list arg;
  46. int n;
  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. }