xref: /minix3/minix/lib/libsys/kputc.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc /* A server must occasionally print some message.  It uses a simple version of
2*433d6423SLionel Sambuc  * printf() found in the system lib that calls kputc() to output characters.
3*433d6423SLionel Sambuc  * Printing is done with a call to the kernel, and not by going through FS.
4*433d6423SLionel Sambuc  *
5*433d6423SLionel Sambuc  * This routine can only be used by servers and device drivers.  The kernel
6*433d6423SLionel Sambuc  * must define its own kputc(). Note that the log driver also defines its own
7*433d6423SLionel Sambuc  * kputc() to directly call the TTY instead of going through this library.
8*433d6423SLionel Sambuc  */
9*433d6423SLionel Sambuc 
10*433d6423SLionel Sambuc #include "sysutil.h"
11*433d6423SLionel Sambuc 
12*433d6423SLionel Sambuc static char print_buf[DIAG_BUFSIZE];	/* output is buffered here */
13*433d6423SLionel Sambuc 
14*433d6423SLionel Sambuc /*===========================================================================*
15*433d6423SLionel Sambuc  *				kputc					     *
16*433d6423SLionel Sambuc  *===========================================================================*/
kputc(int c)17*433d6423SLionel Sambuc void kputc(int c)
18*433d6423SLionel Sambuc {
19*433d6423SLionel Sambuc /* Accumulate another character.  If 0 or buffer full, print it. */
20*433d6423SLionel Sambuc   static int buf_count;		/* # characters in the buffer */
21*433d6423SLionel Sambuc 
22*433d6423SLionel Sambuc   if ((c == 0 && buf_count > 0) || buf_count == sizeof(print_buf)) {
23*433d6423SLionel Sambuc 	sys_diagctl_diag(print_buf, buf_count);
24*433d6423SLionel Sambuc 	buf_count = 0;
25*433d6423SLionel Sambuc   }
26*433d6423SLionel Sambuc   if (c != 0) {
27*433d6423SLionel Sambuc 
28*433d6423SLionel Sambuc         /* Append a single character to the output buffer. */
29*433d6423SLionel Sambuc   	print_buf[buf_count] = c;
30*433d6423SLionel Sambuc 	buf_count++;
31*433d6423SLionel Sambuc   }
32*433d6423SLionel Sambuc }
33