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

login
register
mail settings
Submitter Iulian Stana
Date Sept. 5, 2013, 2:13 p.m.
Message ID <470eea41ab3e0f475633.1378390403@doppler>
Download mbox | patch
Permalink /patch/2334/
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 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.

Patch

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;
+}
+