source: trunk/minix/lib/sysutil/kputc.c@ 10

Last change on this file since 10 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 1.6 KB
Line 
1/* A server must occasionally print some message. It uses a simple version of
2 * printf() found in the system lib that calls kputc() to output characters.
3 * Printing is done with a call to the kernel, and not by going through FS.
4 *
5 * This routine can only be used by servers and device drivers. The kernel
6 * must define its own kputc(). Note that the log driver also defines its own
7 * kputc() to directly call the TTY instead of going through this library.
8 */
9
10#include "sysutil.h"
11
12/*===========================================================================*
13 * kputc *
14 *===========================================================================*/
15void kputc(c)
16int c;
17{
18/* Accumulate another character. If 0 or buffer full, print it. */
19 static int buf_count; /* # characters in the buffer */
20 static char print_buf[80]; /* output is buffered here */
21 message m;
22
23 if ((c == 0 && buf_count > 0) || buf_count == sizeof(print_buf)) {
24 int procs[] = OUTPUT_PROCS_ARRAY;
25 int p;
26
27 for(p = 0; procs[p] != NONE; p++) {
28 /* Send the buffer to this output driver. */
29 m.DIAG_BUF_COUNT = buf_count;
30 m.DIAG_PRINT_BUF = print_buf;
31 m.DIAG_ENDPT = SELF;
32 m.m_type = DIAGNOSTICS;
33 (void) _sendrec(procs[p], &m);
34 }
35 buf_count = 0;
36
37 /* If the output fails, e.g., due to an ELOCKED, do not retry output
38 * at the FS as if this were a normal user-land printf(). This may
39 * result in even worse problems.
40 */
41 }
42 if (c != 0) {
43
44 /* Append a single character to the output buffer. */
45 print_buf[buf_count++] = c;
46 }
47}
Note: See TracBrowser for help on using the repository browser.