1 #include <unistd.h>
2 #include <fcntl.h>
3 
4 #define TRUN_SIZE 3
5 #define TRUNCATE_TEST_NAME "./ftruncate_to3"
6 
ftruncate_entry(void)7 static int ftruncate_entry(void)
8 {
9     int res = 0;
10     int fd = 0;
11 
12     fd = open(TRUNCATE_TEST_NAME, O_RDWR | O_CREAT | O_APPEND);
13     if (fd < 0)
14     {
15         return -1;
16     }
17 
18     write(fd, "hello", 6);
19     /* TODO */
20     res = ftruncate(fd, TRUN_SIZE);
21     close(fd);
22     return res;
23 }
24 
25 #include <utest.h>
26 
test_ftruncate(void)27 static void test_ftruncate(void)
28 {
29     uassert_int_equal(ftruncate_entry(), 0);
30 }
testcase(void)31 static void testcase(void)
32 {
33     UTEST_UNIT_RUN(test_ftruncate);
34 }
35 UTEST_TC_EXPORT(testcase, "posix.unistd_h.ftruncate_tc.c", RT_NULL, RT_NULL, 10);
36 
37