#include <errno.h>
#include "../src/compiler.h"
+#include "example.h"
int main(int argc, char **argv unused) {
errno = ENOMEM;
perror("error!");
- write(STDERR_FILENO, "write to stderr 2", 17);
- write(STDOUT_FILENO, "write to stdout 2", 17);
+ xwrite(STDERR_FILENO, "write to stderr 2", 17);
+ xwrite(STDOUT_FILENO, "write to stdout 2", 17);
fprintf(stderr, "\n");
fprintf(stdout, "\n");
fflush(stdout);
- /* Check usage of tracked_fds_list (at least in parts). No error checking
- * here! */
- dup2(STDERR_FILENO, 471);
- dup2(471, 42);
- write(471, "more on stderr\n", 15);
+ /* Check usage of tracked_fds_list (at least in parts). */
+ xdup2(STDERR_FILENO, 471);
+ xdup2(471, 42);
+ xwrite(471, "more on stderr\n", 15);
close(471);
- dup2(STDOUT_FILENO, 471);
- write(42, "stderr ...\n", 11);
- write(471, "more on stdout\n", 15);
+ xdup2(STDOUT_FILENO, 471);
+ xwrite(42, "stderr ...\n", 11);
+ xwrite(471, "more on stdout\n", 15);
/* Glibc uses __overflow() for this ... */
putc_unlocked('x', stderr);
} \
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;
+}
#include <string.h>
#include <unistd.h>
+#include "example.h"
#include "../src/compiler.h"
printf("\nCHECKING COLORING.\n\n");
fflush(stdout);
- dup2(2, 3);
+ xdup2(2, 3);
char *args[] = { argv0, NULL };
char *envp[] = { ldpreload, NULL };
execve(argv[0], args, envp);
return EXIT_FAILURE;
} else if (!skip--) {
- dup2(2, 4);
+ xdup2(2, 4);
execl(argv[0], argv0, NULL);
return EXIT_FAILURE;
} else if (!skip--) {
- dup2(2, 5);
+ xdup2(2, 5);
execlp(argv[0], argv0, NULL);
return EXIT_FAILURE;
} else if (!skip--) {
- dup2(2, 6);
+ xdup2(2, 6);
char *envp[] = { ldpreload, NULL };
execle(argv[0], argv0, NULL, envp);
return EXIT_FAILURE;
} else if (!skip--) {
- dup2(2, 7);
+ xdup2(2, 7);
/* Test closing a few descriptors. */
close(5);
execv(argv[0], args);
return EXIT_FAILURE;
} else if (!skip--) {
- dup2(2, 8);
+ xdup2(2, 8);
/* And a few more. */
close(7);
close(3);
close(8);
- dup2(2, 5);
+ xdup2(2, 5);
char *args[] = { argv0, NULL };
char *envp[] = { ldpreload, "COLORED_STDERR_FDS=5,", NULL };
char *args[] = { argv0, NULL };
char *envp[] = { ldpreload, NULL };
- dup2(5, 6);
+ xdup2(5, 6);
close(5);
execve(argv[0], args, envp);