[PATCH c-hglib] hg_rawread: reading some unparse data from command server

Iulian Stana julian.stana at gmail.com
Wed Sep 18 17:20:22 CDT 2013


# HG changeset patch
# User Iulian Stana <julian.stana at gmail.com>
# Date 1379453713 -10800
#      Wed Sep 18 00:35:13 2013 +0300
# Node ID 54a75470cc4a33a6a92c71e6dd2bb81572b9c1e6
# Parent  56adaa5609236d29884eab4c1a1799a2692d3306
hg_rawread: reading some unparse data from command server

Will read the data found in the pipe. This function will read min(sizebuff,
bytes_on_pipe).
Users can provide a buffer with a bigger size than the bytes found on the pipe,
you don't want to read more bytes then it must.

diff --git a/hglib/client.c b/hglib/client.c
--- a/hglib/client.c
+++ b/hglib/client.c
@@ -238,4 +238,34 @@
 	return 0;
 }
 
+/*
+ * Reading some unparse data from the server.
+ * */
+int hg_rawread(hg_handle *handle, char *buffer, size_t sizebuff)
+{
+	int length = handle->bytes_on_pipe;
+	hg_header *ch = handle->header;
 
+	if (!handle) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	/* If the current channel is not an input channel return 0. */
+	if (!(ch->channel == o || ch->channel == e)) {
+		return 0;
+	}
+
+	length = (length > sizebuff)? sizebuff : length;
+
+	if (read(handle->p_read, buffer, length) < 0) {
+		return -1;
+	}
+
+	buffer[length] = '\0';
+	handle->bytes_on_pipe -= length;
+
+	return length;
+}
+
+


More information about the Mercurial-devel mailing list