ftruncate.c 555 B

123456789101112131415161718192021222324
  1. #include <unistd.h>
  2. #include <fcntl.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "test_helpers.h"
  6. int main(void) {
  7. int fd = creat("ftruncate.out", 0777);
  8. ERROR_IF(creat, fd, == -1);
  9. UNEXP_IF(creat, fd, < 0);
  10. int status = ftruncate(fd, 100);
  11. ERROR_IF(ftruncate, status, == -1);
  12. UNEXP_IF(ftruncate, status, != 0);
  13. int c = close(fd);
  14. ERROR_IF(close, c, == -1);
  15. UNEXP_IF(close, c, != 0);
  16. status = truncate("ftruncate.out", 100);
  17. ERROR_IF(truncate, status, == -1);
  18. UNEXP_IF(truncate, status, != 0);
  19. }