vbos/kernel/tty/tee.c
Michael Shaw 4909482a2e tty: add tee
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
2026-07-17 02:38:00 -04:00

67 lines
1.2 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
#include <kernel/tty.h>
#include <kernel/slab.h>
#include <lib/list.h>
static void serial_putchar(struct tty *tty, char c)
{
list_t *list = tty->priv;
if (!list)
return;
list_item_t *item = list->head;
while (item) {
struct tty *next = item->ptr;
next->serial_ops.serial_putchar(next, c);
item = item->next;
}
}
static char serial_getchar(struct tty *tty)
{
/* can't read from a tee, duh */
return 0;
}
struct tty *tty_tee_create(const char *name)
{
static struct tty_serial_ops ops = {.serial_putchar = serial_putchar, .serial_getchar = serial_getchar};
list_t *list = kzalloc(sizeof(list_t), ALLOC_KERN);
if (!list)
return NULL;
list_create(list);
struct tty *ret = tty_create(name, list);
if (!ret) {
list_destroy(list);
kfree(list);
return NULL;
}
ret->serial_ops = ops;
return ret;
}
void tty_tee_add(struct tty *tee, struct tty *child)
{
list_t *list = tee->priv;
list_insert(list, child);
}
void tty_tee_remove(struct tty *tee, struct tty *child)
{
list_t *list = tee->priv;
if (!list)
return;
list_item_t *item = list->head;
while (item) {
if (item->ptr == child) {
list_remove(item);
return;
}
item = item->next;
}
}