- g_slist_free(devices);
-
-}
-
-void save_chunk_logic(struct sr_session *session, uint8_t *data,
- uint64_t data_len, int unitsize)
-{
- static uint8_t *buf = NULL;
- static int buf_len = 0;
- static int last_unitsize = 0;
- int max;
-
- if (!buf)
- buf = g_malloc(SAVE_CHUNK_SIZE);
-
- if (buf_len + data_len > SAVE_CHUNK_SIZE) {
- max = (SAVE_CHUNK_SIZE - buf_len) / unitsize * unitsize;
- memcpy(buf + buf_len, data, max);
- sr_session_append(session, opt_output_file, buf, unitsize,
- (buf_len + max) / unitsize);
- memcpy(buf, data + max, data_len - max);
- buf_len = data_len - max;
- } else if (data_len == 0 && last_unitsize != 0) {
- /* End of data, flush the buffer out. */
- sr_session_append(session, opt_output_file, buf, last_unitsize,
- buf_len / last_unitsize);
- } else {
- /* Buffer chunk. */
- memcpy(buf + buf_len, data, data_len);
- buf_len += data_len;
- }
- last_unitsize = unitsize;
-