| 8 | #include <assert.h> |
| 9 | |
| 10 | int main(void) |
| 11 | { |
| 12 | const char *name = "noerr.file"; |
| 13 | int fd; |
| 14 | FILE *fp; |
| 15 | |
| 16 | plan_tests(16); |
| 17 | /* Should fail to unlink. */ |
| 18 | ok1(unlink(name) != 0); |
| 19 | ok1(errno == ENOENT); |
| 20 | |
| 21 | /* This one should not set errno. */ |
| 22 | errno = 100; |
| 23 | ok1(unlink_noerr(name) == ENOENT); |
| 24 | ok1(errno == 100); |
| 25 | |
| 26 | /* Should fail to close. */ |
| 27 | ok1(close(-1) != 0); |
| 28 | ok1(errno == EBADF); |
| 29 | |
| 30 | /* This one should not set errno. */ |
| 31 | errno = 100; |
| 32 | ok1(close_noerr(-1) == EBADF); |
| 33 | ok1(errno == 100); |
| 34 | |
| 35 | /* Test successful close/unlink doesn't hit errno either. */ |
| 36 | fd = open(name, O_WRONLY|O_CREAT|O_EXCL, 0600); |
| 37 | assert(fd >= 0); |
| 38 | |
| 39 | errno = 100; |
| 40 | ok1(close_noerr(fd) == 0); |
| 41 | ok1(errno == 100); |
| 42 | |
| 43 | errno = 100; |
| 44 | ok1(unlink_noerr(name) == 0); |
| 45 | ok1(errno == 100); |
| 46 | |
| 47 | /* Test failing fclose */ |
| 48 | fp = fopen(name, "wb"); |
| 49 | assert(fp); |
| 50 | close(fileno(fp)); |
| 51 | ok1(fclose_noerr(fp) == EBADF); |
| 52 | |
| 53 | /* Test successful fclose */ |
| 54 | fp = fopen(name, "wb"); |
| 55 | assert(fp); |
| 56 | |
| 57 | errno = 100; |
| 58 | ok1(fclose_noerr(fp) == 0); |
| 59 | ok1(errno == 100); |
| 60 | unlink(name); |
| 61 | |
| 62 | errno = 101; |
| 63 | free_noerr(malloc(7)); |
| 64 | ok1(errno == 101); |
| 65 | |
| 66 | return exit_status(); |
| 67 | } |
nothing calls this directly
no test coverage detected