1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-11-13 11:04:27 -05:00
libkernaux/src/console.c

78 lines
1.4 KiB
C
Raw Normal View History

2020-12-06 23:46:37 -05:00
#ifdef HAVE_CONFIG_H
2020-11-30 06:40:33 -05:00
#include "config.h"
2020-12-06 23:46:37 -05:00
#endif
2020-11-30 06:40:33 -05:00
#include <kernaux/assert.h>
#include <kernaux/console.h>
#include "libc.h"
#ifdef ASM_I386
#include <kernaux/asm/i386.h>
2020-11-30 06:32:12 -05:00
#endif
2022-01-11 01:48:54 -05:00
#ifdef ASM_X86_64
#include <kernaux/asm/x86_64.h>
#endif
#ifdef WITH_PRINTF
#include <kernaux/printf.h>
#endif
2020-11-30 06:32:12 -05:00
2022-01-19 07:01:21 -05:00
#include <stddef.h>
2022-01-20 06:34:12 -05:00
#ifdef WITH_PRINTF
2022-01-19 07:04:46 -05:00
static void kernaux_console_printf_putc(
const char c,
void *const arg __attribute__((unused))
) {
kernaux_console_putc(c);
}
2022-01-20 06:34:12 -05:00
#endif
2022-01-19 07:04:46 -05:00
2020-12-05 20:41:31 -05:00
void kernaux_console_putc(const char c __attribute__((unused)))
{
#ifdef ASM_I386
2022-01-23 21:50:16 -05:00
kernaux_asm_i386_outportb(0x3f8, c);
2020-11-30 06:32:12 -05:00
#endif
2022-01-11 01:48:54 -05:00
#ifdef ASM_X86_64
2022-01-23 21:50:16 -05:00
kernaux_asm_x86_64_outportb(0x3f8, c);
2022-01-11 01:48:54 -05:00
#endif
2020-11-30 06:32:12 -05:00
}
void kernaux_console_print(const char *const s)
{
KERNAUX_NOTNULL_RETURN(s);
for (const char *c = s; *c; ++c) {
kernaux_console_putc(*c);
}
}
#ifdef WITH_PRINTF
void kernaux_console_printf(const char *format, ...)
{
KERNAUX_NOTNULL_RETURN(format);
va_list va;
va_start(va, format);
kernaux_vfprintf(kernaux_console_printf_putc, NULL, format, va);
va_end(va);
}
#endif
2020-11-30 06:32:12 -05:00
void kernaux_console_puts(const char *const s)
{
KERNAUX_NOTNULL_RETURN(s);
2020-11-30 06:32:12 -05:00
kernaux_console_print(s);
kernaux_console_putc('\n');
}
2021-12-16 10:26:16 -05:00
void kernaux_console_write(const char *const data, const size_t size)
2020-12-05 20:41:31 -05:00
{
KERNAUX_NOTNULL_RETURN(data);
2021-12-16 10:26:16 -05:00
for (size_t i = 0; i < size; i++) {
2020-11-30 06:32:12 -05:00
kernaux_console_putc(data[i]);
}
}