vbos/usr.bin/shtest/shtest.c
Michael Shaw 3b1dc7e153 usr.bin: add shtest
shtest is a simple userland shell test program that accepts input and
echoes it back to the user
2024-02-19 02:25:34 -05:00

38 lines
598 B
C

/* SPDX-License-Identifier: GPL-2.0-only */
/* shtest: simple userland shell test */
#include <stdint.h>
#include <stddef.h>
typedef int64_t ssize_t;
int open(const char *pathname, int flags);
ssize_t read(int fd, void *buf, int count);
ssize_t write(int fd, void *buf, int count);
int close(int fd);
int exit(int status);
void promptfd(int fd)
{
write(fd, "shtest> ", 8);
}
void _start()
{
int fd = open("/dev/tty", 0);
if (fd < 0)
exit(1);
promptfd(fd);
char c;
while (read(fd, &c, 1) == 1) {
write(fd, &c, 1);
if (c == '\n') {
promptfd(fd);
}
}
close(fd);
exit(0);
}