[PATCH 3 of 6 RFC hglib] detect_null_byte: detect the length to the first '\0' character

Iulian Stana julian.stana at gmail.com
Thu Sep 5 09:13:23 CDT 2013


# HG changeset patch
# User Iulian Stana <julian.stana at gmail.com>
# Date 1378388600 -10800
#      Thu Sep 05 16:43:20 2013 +0300
# Node ID 470eea41ab3e0f4756339c3cc9f1563361224787
# Parent  4307b7b1166b01417bb9e15467c9db16d059484b
detect_null_byte: detect the length to the first '\0' character

Used in detecting the length of the first cset, and also to detect if there is a
cset or not in the buffer pointer.

diff --git a/client.c b/client.c
--- a/client.c
+++ b/client.c
@@ -43,3 +43,30 @@
 
 	return cbuf;
 }
+
+/**
+ * This function will detect the length of the first cset, in other words the 
+ * length to first '\0' character. 
+ * Also this function will tell me if the '\0' character it's the end of string 
+ * character or is a character in the middle of line.
+ *
+ * The function will return 0 in case a cset is not detected or will retrun the 
+ * length of the cset.   
+ **/
+int detect_null_byte(char *buffer, int buf_size, int data_on_pipe)
+{
+	if(buffer == NULL)
+		return 0;
+	char *char_ptr;
+
+	for(char_ptr = buffer; char_ptr < buffer + buf_size; ++char_ptr)
+		if( *char_ptr == '\0')
+			break;
+
+	if((char_ptr - buffer < buf_size && data_on_pipe) || 
+		(char_ptr - buffer <= buf_size && !data_on_pipe))
+		return char_ptr - buffer;
+
+	return 0;
+}
+


More information about the Mercurial-devel mailing list