Patchwork [1,of,6,RFC,hglib] append_data: erase_cset: save and release space

login
register
mail settings
Submitter Iulian Stana
Date Sept. 5, 2013, 2:13 p.m.
Message ID <f9378d0bd4c029c52c50.1378390401@doppler>
Download mbox | patch
Permalink /patch/2335/
State Deferred, archived
Headers show

Comments

Iulian Stana - Sept. 5, 2013, 2:13 p.m.
# HG changeset patch
# User Iulian Stana <julian.stana@gmail.com>
# Date 1378381678 -10800
#      Thu Sep 05 14:47:58 2013 +0300
# Node ID f9378d0bd4c029c52c50ee5205255f24e2073a6d
# Parent  0000000000000000000000000000000000000000
append_data: erase_cset: save and release space.

You must save somewhere your data in order to parse the cset and to pass it to
user.

append_data will add to a specific place the data that you already read from
command server.

erase_cset will release this data after you pass it to user. This function will
release just of part of the entire data. In your storege place you can have more
than one cset, this function will release as much data, as you think that it's
needed to release.

Patch

diff --git a/client.c b/client.c
new file mode 100644
--- /dev/null
+++ b/client.c
@@ -0,0 +1,24 @@ 
+
+/** 
+ * Adding to the destination pointer the source pointer. 
+ **/
+int append_data(char **dest, char *source, int dsize, int ssize)
+{
+	*dest = realloc(*dest, dsize + ssize + 2);
+	memcpy(*dest + dsize, source, ssize + 1);
+	return 0;
+}
+
+/** 
+ * Erase the top cset from buff pointer. 
+ * After you send a cset, you need to release that memory. 
+ **/
+int erase_cset(char **buff, int buf_size, int first_cset_size)
+{
+	int new_buff_size = buf_size - first_cset_size;
+	char *new_buff = malloc(new_buff_size + 1);
+	memcpy(new_buff, *buff + first_cset_size, new_buff_size + 1);
+	free(*buff);
+	*buff = new_buff;
+	return new_buff_size;
+}