Files
RedBear-OS/recipes/tests/termios.c
T
vasilito b9874d0941 feat: USB storage read/write proof + full Red Bear OS tree sync
Add redbear-usb-storage-check in-guest binary that validates USB mass
storage read and write I/O: discovers /scheme/disk/ devices, writes a
test pattern to sector 2048, reads it back, verifies match, restores
original content. Updates test-usb-storage-qemu.sh with write-proof
verification step.

Includes all accumulated Red Bear OS work: kernel patches, relibc
patches, driver infrastructure, DRM/GPU, KDE recipes, firmware,
validation tooling, build system hardening, and documentation.
2026-05-03 23:03:24 +01:00

58 lines
1.5 KiB
C

#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
int main(void) {
// Check that the tty supports VDISABLE
int vdisable = pathconf("/dev/tty", _PC_VDISABLE);
assert(vdisable == _POSIX_VDISABLE);
int termfd = open("/dev/tty", O_RDWR, O_NDELAY | O_NOCTTY);
if (termfd < 0) {
perror("open");
return EXIT_FAILURE;
}
// Currently set/default options
struct termios termios = {0};
if (tcgetattr(termfd, &termios) < 0) {
perror("tcgetattr");
close(termfd);
return EXIT_FAILURE;
}
struct termios term_restore = termios;
const cc_t verase = termios.c_cc[VERASE];
assert(verase != _POSIX_VDISABLE);
// Disable backspace key control char
termios.c_cc[VERASE] = _POSIX_VDISABLE;
if (tcsetattr(termfd, TCSANOW, &termios) < 0) {
perror("tcsetattr (setting VDISABLE)");
close(termfd);
return EXIT_FAILURE;
}
// Check that it was actually set
struct termios term_vdisable = {0};
if (tcgetattr(termfd, &term_vdisable) < 0) {
perror("tcgetattr (after setting VDISABLE)");
close(termfd);
return EXIT_FAILURE;
}
assert(term_vdisable.c_cc[VERASE] == _POSIX_VDISABLE);
// Restore old config
if (tcsetattr(termfd, TCSAFLUSH, &term_restore) < 0) {
perror("tcsetattr (restoring settings)");
close(termfd);
return EXIT_FAILURE;
}
close(termfd);
return EXIT_SUCCESS;
}