fcntl.c 737 B

12345678910111213141516171819202122232425262728293031
  1. #include <fcntl.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include "test_helpers.h"
  5. int main(void) {
  6. // Lose our fd and pull it again
  7. {
  8. int fd = creat("fcntl.out", 0777);
  9. ERROR_IF(creat, fd, == -1);
  10. UNEXP_IF(creat, fd, < 0);
  11. }
  12. int newfd = open("fcntl.out", 0);
  13. ERROR_IF(open, newfd, == -1);
  14. UNEXP_IF(open, newfd, < 0);
  15. int newfd2 = fcntl(newfd, F_DUPFD, 0);
  16. // TODO: The standard doesn't define errors for F_DUPFD
  17. printf("duped fd is %d greater than the original fd\n", newfd2 - newfd);
  18. int c1 = close(newfd);
  19. ERROR_IF(close, c1, == -1);
  20. UNEXP_IF(close, c1, != 0);
  21. int c2 = close(newfd2);
  22. ERROR_IF(close, c2, == -1);
  23. UNEXP_IF(close, c2, != 0);
  24. }