wintest: add option to select the dns backend
[Samba/gebeck_regimport.git] / lib / ccan / read_write_all / test / run-write_all.c
blobe2baf48dfe79893a9729b749516ebcdd3704c61e
1 #include <ccan/read_write_all/read_write_all.h>
2 #include <ccan/tap/tap.h>
3 #include <unistd.h>
4 #include <sys/types.h>
5 #include <signal.h>
6 #include <limits.h>
7 #include <sys/wait.h>
8 #include <err.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <stdio.h>
13 static ssize_t test_write(int fd, const void *buf, size_t count);
14 #define write test_write
15 #include <ccan/read_write_all/read_write_all.c>
16 #undef write
18 static ssize_t write_return;
20 static ssize_t test_write(int fd, const void *buf, size_t count)
22 if (write_return == 0) {
23 errno = ENOSPC;
24 return 0;
27 if (write_return < 0) {
28 errno = -write_return;
29 /* Don't return EINTR more than once! */
30 if (errno == EINTR)
31 write_return = count;
32 return -1;
35 if (write_return < count)
36 return write_return;
37 return count;
40 #define BUFSZ 1024
42 int main(int argc, char *argv[])
44 char *buffer;
46 buffer = malloc(BUFSZ);
47 plan_tests(8);
49 write_return = -ENOSPC;
50 ok1(!write_all(100, buffer, BUFSZ));
51 ok1(errno == ENOSPC);
53 write_return = -EINTR;
54 ok1(write_all(100, buffer, BUFSZ));
55 ok1(errno == EINTR);
57 write_return = 1;
58 errno = 0;
59 ok1(write_all(100, buffer, BUFSZ));
60 ok1(errno == 0);
62 write_return = BUFSZ;
63 ok1(write_all(100, buffer, BUFSZ));
64 ok1(errno == 0);
65 free(buffer);
67 return exit_status();