#include "common.h" #define EXTEND_SIZE 4097 void seek_input_fd(const char* path) { int f = open_input_fd(path); printf("open(%s) input OK\n", path); seek_fd(path, f, 0, SEEK_SET); printf("seek(%s) input start OK\n", path); seek_fd(path, f, 0, SEEK_END); printf("seek(%s) input end OK\n", path); off_t pos = tell_fd(path, f); printf("tell(%s) input end OK: %zd\n", path, pos); seek_fd(path, f, -pos, SEEK_END); // rewind printf("seek(%s) input rewind OK\n", path); pos = tell_fd(path, f); printf("tell(%s) input start OK: %zd\n", path, pos); close_fd(path, f); printf("close(%s) input OK\n", path); } void seek_input_stdio(const char* path) { FILE* f = open_input_stdio(path); printf("fopen(%s) input OK\n", path); seek_stdio(path, f, 0, SEEK_SET); printf("fseek(%s) input start OK\n", path); seek_stdio(path, f, 0, SEEK_END); printf("fseek(%s) input end OK\n", path); off_t pos = tell_stdio(path, f); printf("ftell(%s) input end OK: %zd\n", path, pos); seek_stdio(path, f, -pos, SEEK_END); // rewind printf("fseek(%s) input rewind OK\n", path); pos = tell_stdio(path, f); printf("ftell(%s) input start OK: %zd\n", path, pos); close_stdio(path, f); printf("fclose(%s) input OK\n", path); } void seek_output_fd(const char* path) { uint8_t buf[EXTEND_SIZE + 1] = {1}; int f = open_output_fd(path, /*rdwr=*/true); printf("open(%s) output OK\n", path); seek_fd(path, f, 0, SEEK_SET); printf("seek(%s) output start OK\n", path); seek_fd(path, f, 0, SEEK_END); printf("seek(%s) output end OK\n", path); off_t pos = tell_fd(path, f); printf("tell(%s) output end OK: %zd\n", path, pos); seek_fd(path, f, EXTEND_SIZE, SEEK_CUR); // extend printf("seek(%s) output end 2 OK\n", path); write_fd(path, f, buf, 1); seek_fd(path, f, -EXTEND_SIZE - 1, SEEK_CUR); // rewind to former end printf("seek(%s) output end 3 OK\n", path); read_fd(path, f, buf, EXTEND_SIZE + 1); for (size_t i=0; i \n", argv[0]); setup(); seek_input_fd(argv[1]); seek_input_stdio(argv[1]); seek_output_fd(argv[2]); seek_output_stdio(argv[3]); return 0; }