00001 #include <stdio.h>
00002 #include <string.h>
00003 #include <syscall.h>
00004 #include <syscall-nr.h>
00005
00006
00007
00008 int
00009 vprintf (const char *format, va_list args)
00010 {
00011 return vhprintf (STDOUT_FILENO, format, args);
00012 }
00013
00014
00015 int
00016 hprintf (int handle, const char *format, ...)
00017 {
00018 va_list args;
00019 int retval;
00020
00021 va_start (args, format);
00022 retval = vhprintf (handle, format, args);
00023 va_end (args);
00024
00025 return retval;
00026 }
00027
00028
00029
00030 int
00031 puts (const char *s)
00032 {
00033 write (STDOUT_FILENO, s, strlen (s));
00034 putchar ('\n');
00035
00036 return 0;
00037 }
00038
00039
00040 int
00041 putchar (int c)
00042 {
00043 char c2 = c;
00044 write (STDOUT_FILENO, &c2, 1);
00045 return c;
00046 }
00047
00048
00049 struct vhprintf_aux
00050 {
00051 char buf[64];
00052 char *p;
00053 int char_cnt;
00054 int handle;
00055 };
00056
00057 static void add_char (char, void *);
00058 static void flush (struct vhprintf_aux *);
00059
00060
00061
00062
00063 int
00064 vhprintf (int handle, const char *format, va_list args)
00065 {
00066 struct vhprintf_aux aux;
00067 aux.p = aux.buf;
00068 aux.char_cnt = 0;
00069 aux.handle = handle;
00070 __vprintf (format, args, add_char, &aux);
00071 flush (&aux);
00072 return aux.char_cnt;
00073 }
00074
00075
00076
00077 static void
00078 add_char (char c, void *aux_)
00079 {
00080 struct vhprintf_aux *aux = aux_;
00081 *aux->p++ = c;
00082 if (aux->p >= aux->buf + sizeof aux->buf)
00083 flush (aux);
00084 aux->char_cnt++;
00085 }
00086
00087
00088 static void
00089 flush (struct vhprintf_aux *aux)
00090 {
00091 if (aux->p > aux->buf)
00092 write (aux->handle, aux->buf, aux->p - aux->buf);
00093 aux->p = aux->buf;
00094 }