Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4376 → Rev 4377

/branches/tracing/kernel/generic/src/printf/vprintf.c
26,7 → 26,7
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup generic
/** @addtogroup generic
* @{
*/
/** @file
39,36 → 39,66
#include <arch/asm.h>
#include <arch/types.h>
#include <typedefs.h>
#include <string.h>
 
SPINLOCK_INITIALIZE(printf_lock); /**< vprintf spinlock */
SPINLOCK_INITIALIZE(printf_lock); /**< vprintf spinlock */
 
static int vprintf_write(const char *str, size_t count, void *unused)
static int vprintf_str_write(const char *str, size_t size, void *data)
{
size_t i;
for (i = 0; i < count; i++)
putchar(str[i]);
return i;
size_t offset = 0;
count_t chars = 0;
while (offset < size) {
putchar(str_decode(str, &offset, size));
chars++;
}
return chars;
}
 
int puts(const char *s)
static int vprintf_wstr_write(const wchar_t *str, size_t size, void *data)
{
size_t i;
for (i = 0; s[i] != 0; i++)
putchar(s[i]);
return i;
size_t offset = 0;
count_t chars = 0;
while (offset < size) {
putchar(str[chars]);
chars++;
offset += sizeof(wchar_t);
}
return chars;
}
 
int puts(const char *str)
{
size_t offset = 0;
count_t chars = 0;
wchar_t uc;
while ((uc = str_decode(str, &offset, STR_NO_LIMIT)) != 0) {
putchar(uc);
chars++;
}
return chars;
}
 
int vprintf(const char *fmt, va_list ap)
{
struct printf_spec ps = {(int(*)(void *, size_t, void *)) vprintf_write, NULL};
printf_spec_t ps = {
vprintf_str_write,
vprintf_wstr_write,
NULL
};
int irqpri = interrupts_disable();
ipl_t ipl = interrupts_disable();
spinlock_lock(&printf_lock);
int ret = printf_core(fmt, &ps, ap);
spinlock_unlock(&printf_lock);
interrupts_restore(irqpri);
interrupts_restore(ipl);
return ret;
}