Dup stdout rather than opening /dev/stdout.
The former is more portable, even on Linux if for example sudo/doas is used.
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "test_helpers.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int fd = open("/dev/stdout", O_WRONLY, 0222);
|
||||
ERROR_IF(open, fd, < 0);
|
||||
|
||||
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);
|
||||
@@ -21,4 +20,4 @@ int main(void)
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user