1 #include <ccan/noerr/noerr.h>
2 #include <ccan/tap/tap.h>
3 #include <ccan/noerr/noerr.c>
10 int main(int argc, char *argv[])
12 const char *name = "noerr.file";
17 /* Should fail to unlink. */
18 ok1(unlink(name) != 0);
21 /* This one should not set errno. */
23 ok1(unlink_noerr(name) == ENOENT);
26 /* Should fail to close. */
30 /* This one should not set errno. */
32 ok1(close_noerr(-1) == EBADF);
35 /* Test successful close/unlink doesn't hit errno either. */
36 fd = open(name, O_WRONLY|O_CREAT|O_EXCL, 0600);
40 ok1(close_noerr(fd) == 0);
44 ok1(unlink_noerr(name) == 0);
47 /* Test failing fclose */
48 fp = fopen(name, "wb");
51 ok1(fclose_noerr(fp) == EBADF);
53 /* Test successful fclose */
54 fp = fopen(name, "wb");
58 ok1(fclose_noerr(fp) == 0);