int main() { FILE *tp = fopen("db_file.txt", "wb"); fwrite("abcdBbcdaD", sizeof(unsigned char), 10, tp); fclose(tp); tuple_buffer* p = buf_create("db_file.txt"); printf("%d\n", buf_get_int(p)); printf("%c\n", buf_get_char(p)); printf("%d\n", buf_get_int(p)); printf("%c\n", buf_get_char(p)); buf_remove(p); printf("%d\n",0x64636261); printf("%d\n", 0x61646362); return 0; }
void fixed_gap_arena_remove(FixedGapArena *arena, memi offset, memi size) { // TODO: Decide how much we want to protect the API. // This one is public, so maybe allow more protection? if (size == 0) { return; } hale_assert_input((offset + size) <= arena->size); hale_assert_input(offset <= arena->size); Buf *it0 = vector_begin(&arena->buffers); Buf *end = vector_end(&arena->buffers); it0 = find_buf_GT(arena, &offset, it0, end); hale_assert_requirement(it0 != end); memi length = buf_length(it0); if ((offset + size) < length) { buf_remove(it0, offset, size); } else { memi p2 = size; if (offset != 0) { p2 -= buf_remove(it0, offset, length - offset); ++it0; } if (p2) { Buf *itE = it0; length = buf_length(it0); if (p2 == length) { p2 = 0; ++itE; } else // if (p2) { while (length < p2) { p2 -= length; ++itE; if (itE == end) { break; } length = buf_length(itE); } if (p2) { buf_remove(itE, 0, p2); } } if (it0 != itE) { if (vector_count(&arena->buffers) == 1) { // Do not remove the first buffer. // Requirement for `insert`. buf_clear(it0); } else { vector_remove(&arena->buffers, it0, itE); } } } } arena->size -= size; }