X-Git-Url: https://ruderich.org/simon/gitweb/?p=coloredstderr%2Fcoloredstderr.git;a=blobdiff_plain;f=tests%2Fexample.h;h=3d5268f5524d2d6563483809d30dd7e618481d76;hp=facbc30d5b4660170981751fb0fc92f0ffc9d52f;hb=8a65b4486febf00e3fad5bafc3773a811e675a4c;hpb=941370dda9f22ca42e1d5b3cd580d7e7091d40bc diff --git a/tests/example.h b/tests/example.h index facbc30..3d5268f 100644 --- a/tests/example.h +++ b/tests/example.h @@ -1,7 +1,7 @@ /* * Helper functions/macros for example files. * - * Copyright (C) 2013 Simon Ruderich + * Copyright (C) 2013-2015 Simon Ruderich * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -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; +}