delete.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "common.h"
  2. void file_delete(const char* file_path_1, const char* file_path_2, bool writable) {
  3. const char* type = writable ? "output" : "input";
  4. int fd = writable ? open_output_fd(file_path_1, /*rdwr=*/false) : open_input_fd(file_path_1);
  5. printf("open(%s) %s 1 OK\n", file_path_1, type);
  6. close_fd(file_path_1, fd);
  7. printf("close(%s) %s 1 OK\n", file_path_1, type);
  8. if (unlink(file_path_1) != 0)
  9. fatal_error("Failed to unlink file %s: %s\n", file_path_1, strerror(errno));
  10. printf("unlink(%s) %s 1 OK\n", file_path_1, type);
  11. fd = writable ? open_output_fd(file_path_2, /*rdwr=*/false) : open_input_fd(file_path_2);
  12. printf("open(%s) %s 2 OK\n", file_path_2, type);
  13. if (unlink(file_path_2) != 0)
  14. fatal_error("Failed to unlink file %s: %s\n", file_path_2, strerror(errno));
  15. printf("unlink(%s) %s 2 OK\n", file_path_2, type);
  16. close_fd(file_path_2, fd);
  17. printf("close(%s) %s 2 OK\n", file_path_2, type);
  18. }
  19. int main(int argc, char* argv[])
  20. {
  21. if (argc < 6)
  22. fatal_error("Usage: %s <path1> <path2> <path3> <path4> <path5>\n", argv[0]);
  23. setup();
  24. if (unlink(argv[1]) != 0)
  25. fatal_error("Failed to unlink file %s: %s\n", argv[1], strerror(errno));
  26. printf("unlink(%s) OK\n", argv[1]);
  27. file_delete(argv[2], argv[3], /*writable=*/false);
  28. file_delete(argv[4], argv[5], /*writable=*/true);
  29. return 0;
  30. }