X-Git-Url: https://ruderich.org/simon/gitweb/?p=coloredstderr%2Fcoloredstderr.git;a=blobdiff_plain;f=tests%2Fexample.h;h=7c27c5aa62ace74b330d2e84b778ab8d74760da3;hp=facbc30d5b4660170981751fb0fc92f0ffc9d52f;hb=219a9882ba55e2dc60f0ab40a2a3afcc7130417c;hpb=0d7f3068981f2b08e583cec21d9069e97c73addd diff --git a/tests/example.h b/tests/example.h index facbc30..7c27c5a 100644 --- a/tests/example.h +++ b/tests/example.h @@ -36,3 +36,22 @@ } \ fflush(stdout); \ } else + +static ssize_t xwrite(int fd, void const *buf, size_t count) { + ssize_t result = write(fd, buf, count); + if (result == -1) { + perror("write"); + exit(EXIT_FAILURE); + } + /* Ignore short writes here. Doesn't matter for test cases. */ + return result; +} + +static int xdup2(int oldfd, int newfd) { + int result = dup2(oldfd, newfd); + if (result == -1) { + perror("dup2"); + exit(EXIT_FAILURE); + } + return result; +}