klog.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2006 Josef Cejka
00003  * Copyright (c) 2006 Jakub Vana
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  *
00010  * - Redistributions of source code must retain the above copyright
00011  *   notice, this list of conditions and the following disclaimer.
00012  * - Redistributions in binary form must reproduce the above copyright
00013  *   notice, this list of conditions and the following disclaimer in the
00014  *   documentation and/or other materials provided with the distribution.
00015  * - The name of the author may not be used to endorse or promote products
00016  *   derived from this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00019  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00020  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00021  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00023  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00024  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00025  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00026  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00027  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00036 #include <libc.h>
00037 #include <str.h>
00038 #include <sys/types.h>
00039 #include <unistd.h>
00040 #include <errno.h>
00041 #include <io/klog.h>
00042 #include <io/printf_core.h>
00043 
00044 size_t klog_write(const void *buf, size_t size)
00045 {
00046         ssize_t ret = (ssize_t) __SYSCALL3(SYS_KLOG, 1, (sysarg_t) buf, size);
00047         
00048         if (ret >= 0)
00049                 return (size_t) ret;
00050         
00051         return 0;
00052 }
00053 
00054 void klog_update(void)
00055 {
00056         (void) __SYSCALL3(SYS_KLOG, 1, (uintptr_t) NULL, 0);
00057 }
00058 
00066 int klog_printf(const char *fmt, ...)
00067 {
00068         va_list args;
00069         va_start(args, fmt);
00070         
00071         int ret = klog_vprintf(fmt, args);
00072         
00073         va_end(args);
00074         
00075         return ret;
00076 }
00077 
00078 static int klog_vprintf_str_write(const char *str, size_t size, void *data)
00079 {
00080         size_t wr = klog_write(str, size);
00081         return str_nlength(str, wr);
00082 }
00083 
00084 static int klog_vprintf_wstr_write(const wchar_t *str, size_t size, void *data)
00085 {
00086         size_t offset = 0;
00087         size_t chars = 0;
00088         
00089         while (offset < size) {
00090                 char buf[STR_BOUNDS(1)];
00091                 size_t sz = 0;
00092                 
00093                 if (chr_encode(str[chars], buf, &sz, STR_BOUNDS(1)) == EOK)
00094                         klog_write(buf, sz);
00095                 
00096                 chars++;
00097                 offset += sizeof(wchar_t);
00098         }
00099         
00100         return chars;
00101 }
00102 
00111 int klog_vprintf(const char *fmt, va_list ap)
00112 {
00113         printf_spec_t ps = {
00114                 klog_vprintf_str_write,
00115                 klog_vprintf_wstr_write,
00116                 NULL
00117         };
00118         
00119         return printf_core(fmt, &ps, ap);
00120 }
00121 

Generated on Thu Jun 2 07:45:41 2011 for HelenOS/USB by  doxygen 1.4.7