Files
RedBear-OS/recipes/tests/unistd/dup.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

47 lines
1.0 KiB
C

#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include "test_helpers.h"
int main(void) {
int fd0 = creat("dup.out", 0777);
ERROR_IF(creat, fd0, == -1);
UNEXP_IF(creat, fd0, < 0);
int fd1 = open("dup.out", 0);
ERROR_IF(open, fd1, == -1);
UNEXP_IF(open, fd1, < 0);
int fd2 = dup(fd1);
ERROR_IF(dup, fd2, == -1);
UNEXP_IF(dup, fd2, < 0);
printf("duped fd is %d greater than the original fd\n", fd2 - fd1);
int c1 = close(fd1);
ERROR_IF(close, c1, == -1);
UNEXP_IF(close, c1, != 0);
int c2 = close(fd2);
ERROR_IF(close, c2, == -1);
UNEXP_IF(close, c2, != 0);
int fd3 = open("dup.out", O_RDWR);
ERROR_IF(open, fd3, == -1);
UNEXP_IF(open, fd3, < 0);
int fd4 = dup2(fd3, 1);
ERROR_IF(dup2, fd4, == -1);
UNEXP_IF(dup2, fd4, < 0);
int p = printf("hello fd %d", fd3);
ERROR_IF(printf, p, == -1);
UNEXP_IF(printf, p, < 0);
int c3 = close(fd3);
ERROR_IF(close, c3, == -1);
UNEXP_IF(close, c3, != 0);
}