ftruncate_tc.c 651 B

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