open_close.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #include "common.h"
  2. void open_close_input_fd(const char* input_path) {
  3. int fi = open_input_fd(input_path);
  4. printf("open(%s) input OK\n", input_path);
  5. close_fd(input_path, fi);
  6. printf("close(%s) input OK\n", input_path);
  7. int f1 = open_input_fd(input_path);
  8. printf("open(%s) input 1 OK\n", input_path);
  9. int f2 = open_input_fd(input_path);
  10. printf("open(%s) input 2 OK\n", input_path);
  11. close_fd(input_path, f1);
  12. printf("close(%s) input 1 OK\n", input_path);
  13. close_fd(input_path, f2);
  14. printf("close(%s) input 2 OK\n", input_path);
  15. }
  16. void open_close_input_stdio(const char* input_path) {
  17. FILE* fi = open_input_stdio(input_path);
  18. printf("fopen(%s) input OK\n", input_path);
  19. close_stdio(input_path, fi);
  20. printf("fclose(%s) input OK\n", input_path);
  21. FILE* f1 = open_input_stdio(input_path);
  22. printf("fopen(%s) input 1 OK\n", input_path);
  23. FILE* f2 = open_input_stdio(input_path);
  24. printf("fopen(%s) input 2 OK\n", input_path);
  25. close_stdio(input_path, f1);
  26. printf("fclose(%s) input 1 OK\n", input_path);
  27. close_stdio(input_path, f2);
  28. printf("fclose(%s) input 2 OK\n", input_path);
  29. }
  30. void open_close_output_fd(const char* output_path) {
  31. int fo = open_output_fd(output_path, /*rdwr=*/false);
  32. printf("open(%s) output OK\n", output_path);
  33. close_fd(output_path, fo);
  34. printf("close(%s) output OK\n", output_path);
  35. int f1 = open_output_fd(output_path, /*rdwr=*/false);
  36. printf("open(%s) output 1 OK\n", output_path);
  37. int f2 = open_output_fd(output_path, /*rdwr=*/false);
  38. printf("open(%s) output 2 OK\n", output_path);
  39. close_fd(output_path, f1);
  40. printf("close(%s) output 1 OK\n", output_path);
  41. close_fd(output_path, f2);
  42. printf("close(%s) output 2 OK\n", output_path);
  43. }
  44. void open_close_output_stdio(const char* output_path) {
  45. FILE* fo = open_output_stdio(output_path, /*rdwr=*/false);
  46. printf("fopen(%s) output OK\n", output_path);
  47. close_stdio(output_path, fo);
  48. printf("fclose(%s) output OK\n", output_path);
  49. FILE* f1 = open_output_stdio(output_path, /*rdwr=*/false);
  50. printf("fopen(%s) output 1 OK\n", output_path);
  51. FILE* f2 = open_output_stdio(output_path, /*rdwr=*/false);
  52. printf("fopen(%s) output 2 OK\n", output_path);
  53. close_stdio(output_path, f1);
  54. printf("fclose(%s) output 1 OK\n", output_path);
  55. close_stdio(output_path, f2);
  56. printf("fclose(%s) output 2 OK\n", output_path);
  57. }
  58. int main(int argc, char* argv[]) {
  59. if (argc < 3)
  60. fatal_error("Usage: %s <input_path> <output_path>\n", argv[0]);
  61. setup();
  62. open_close_input_fd(argv[1]);
  63. open_close_input_stdio(argv[1]);
  64. open_close_output_fd(argv[2]);
  65. open_close_output_stdio(argv[2]);
  66. return 0;
  67. }