fdopen_tc.c 675 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <fcntl.h>
  4. static int fdopen_entry(void)
  5. {
  6. int fd;
  7. FILE *stream;
  8. fd = open("fdopen_file.txt", O_CREAT | O_RDWR | O_APPEND);
  9. if (fd < 0)
  10. {
  11. printf("open fail.\n");
  12. return -1;
  13. }
  14. /* TODO */
  15. stream = fdopen(fd, "w");
  16. if (stream == NULL)
  17. {
  18. printf("fdopen fail.\n");
  19. return -1;
  20. }
  21. fclose(stream);
  22. return 0;
  23. }
  24. #include <utest.h>
  25. static void test_fdopen(void)
  26. {
  27. uassert_int_equal(fdopen_entry(), 0);
  28. }
  29. static void testcase(void)
  30. {
  31. UTEST_UNIT_RUN(test_fdopen);
  32. }
  33. UTEST_TC_EXPORT(testcase, "posix.stdio_h.fdopen_tc.c", RT_NULL, RT_NULL, 10);