run.c 978 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "noerr/noerr.h"
  2. #include "tap.h"
  3. #include "noerr/noerr.c"
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7. #include <stdio.h>
  8. #include <assert.h>
  9. int main(int argc, char *argv[])
  10. {
  11. /* tempnam(3) is generally a bad idea, but OK here. */
  12. char *name = tempnam(NULL, "noerr");
  13. int fd;
  14. plan_tests(12);
  15. /* Should fail to unlink. */
  16. ok1(unlink(name) != 0);
  17. ok1(errno == ENOENT);
  18. /* This one should not set errno. */
  19. errno = 100;
  20. ok1(unlink_noerr(name) == ENOENT);
  21. ok1(errno == 100);
  22. /* Should fail to close. */
  23. ok1(close(-1) != 0);
  24. ok1(errno == EBADF);
  25. /* This one should not set errno. */
  26. errno = 100;
  27. ok1(close_noerr(-1) == EBADF);
  28. ok1(errno == 100);
  29. /* Test successful close/unlink doesn't hit errno either. */
  30. fd = open(name, O_WRONLY|O_CREAT|O_EXCL, 0600);
  31. assert(fd >= 0);
  32. errno = 100;
  33. ok1(close_noerr(fd) == 0);
  34. ok1(errno == 100);
  35. errno = 100;
  36. ok1(unlink_noerr(name) == 0);
  37. ok1(errno == 100);
  38. return exit_status();
  39. }