Files
RedBear-OS/tests/stdio/dprintf.c
T
4lDO2 70e31a9454 Dup stdout rather than opening /dev/stdout.
The former is more portable, even on Linux if for example sudo/doas is used.
2024-08-10 13:00:13 +02:00

24 lines
486 B
C

#include <stdio.h>
#include <unistd.h>
#include "test_helpers.h"
int main(void) {
const char *msg = "Hello, %s";
int fd = dup(STDOUT_FILENO);
ERROR_IF(dup, fd, == -1);
int result = dprintf(fd, msg, "world");
ERROR_IF(dprintf, result, != sizeof("Hello, world") - 1);
UNEXP_IF(dprintf, result, < 0);
result = dprintf(fd, "\na\n");
UNEXP_IF(dprintf, result, < 0);
ERROR_IF(dprintf, result, != sizeof("\na\n") - 1);
close(fd);
return 0;
}