print.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <plan9.h>
  10. #define SIZE 4096
  11. extern int printcol;
  12. int
  13. print(char *fmt, ...)
  14. {
  15. char buf[SIZE], *out;
  16. va_list arg, temp;
  17. int n;
  18. va_start(arg, fmt);
  19. va_copy(temp, arg);
  20. out = doprint(buf, buf+SIZE, fmt, &temp);
  21. va_end(temp);
  22. va_end(arg);
  23. n = write(1, buf, (int32_t)(out-buf));
  24. return n;
  25. }
  26. int
  27. fprint(int f, char *fmt, ...)
  28. {
  29. char buf[SIZE], *out;
  30. va_list arg, temp;
  31. int n;
  32. va_start(arg, fmt);
  33. va_copy(temp, arg);
  34. out = doprint(buf, buf+SIZE, fmt, &temp);
  35. va_end(temp);
  36. va_end(arg);
  37. n = write(f, buf, (int32_t)(out-buf));
  38. return n;
  39. }
  40. int
  41. sprint(char *buf, char *fmt, ...)
  42. {
  43. char *out;
  44. va_list arg, temp;
  45. int scol;
  46. scol = printcol;
  47. va_start(arg, fmt);
  48. va_copy(temp, arg);
  49. out = doprint(buf, buf+SIZE, fmt, &temp);
  50. va_end(temp);
  51. va_end(arg);
  52. printcol = scol;
  53. return out-buf;
  54. }
  55. int
  56. snprint(char *buf, int len, char *fmt, ...)
  57. {
  58. char *out;
  59. va_list arg, temp;
  60. int scol;
  61. scol = printcol;
  62. va_start(arg, fmt);
  63. va_copy(temp, arg);
  64. out = doprint(buf, buf+len, fmt, &temp);
  65. va_end(temp);
  66. va_end(arg);
  67. printcol = scol;
  68. return out-buf;
  69. }
  70. char*
  71. seprint(char *buf, char *e, char *fmt, ...)
  72. {
  73. char *out;
  74. va_list arg, temp;
  75. int scol;
  76. scol = printcol;
  77. va_start(arg, fmt);
  78. va_copy(temp, arg);
  79. out = doprint(buf, e, fmt, &temp);
  80. va_end(temp);
  81. va_end(arg);
  82. printcol = scol;
  83. return out;
  84. }