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