int write_to_body_all(BodyHandle handle, const char *buf, size_t len) {
  size_t total_written = 0;
  while (total_written < len) {
    const char *chunk = buf + total_written;
    size_t chunk_len = len - total_written;
    size_t nwritten = 0;
    int result = xqd_body_write(handle, chunk, chunk_len, BodyWriteEndBack, &nwritten);
    if (result != 0) {
      return result;
    }
    total_written += nwritten;
  }

  return 0;
}
int write_to_body_all(BodyHandle handle, const char *buf, size_t len) {
  size_t total_written = 0;
  while (total_written < len) {
    const char *chunk = buf + total_written;
    size_t chunk_len = len - total_written;
    size_t nwritten = 0;
    int result = xqd_body_write(handle, chunk, chunk_len, BodyWriteEndBack, &nwritten);
    if (result != 0) {
      return result;
    }
    total_written += nwritten;
  }

  return 0;
}