2
0

rename.c 634 B

123456789101112131415161718192021222324252627282930
  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <unistd.h>
  6. #include "test_helpers.h"
  7. static char oldpath[] = "old-name.out";
  8. static char newpath[] = "new-name.out";
  9. static char str[] = "Hello, World!";
  10. int str_len = 13;
  11. int main(void) {
  12. char buf[14];
  13. buf[13] = 0x00;
  14. int fd = creat(oldpath, 0777);
  15. write(fd, str, str_len);
  16. close(fd);
  17. rename(oldpath, newpath);
  18. fd = open(newpath, O_RDONLY);
  19. read(fd, buf, str_len);
  20. close(fd);
  21. remove(newpath);
  22. if (strcmp(str, buf) == 0) {
  23. exit(EXIT_SUCCESS);
  24. } else {
  25. exit(EXIT_FAILURE);
  26. }
  27. }