Index: uspace/lib/http/src/receive-buffer.c
===================================================================
--- uspace/lib/http/src/receive-buffer.c	(revision 408424e4d6ecbd4f4fe51e827379f230a7e6618e)
+++ uspace/lib/http/src/receive-buffer.c	(revision 82d515e917f3eeeff253e4aa30e493f5f632c950)
@@ -61,7 +61,9 @@
 }
 
-static ssize_t dummy_receive(void *unused, void *buf, size_t buf_size)
-{
-	return 0;
+static int dummy_receive(void *unused, void *buf, size_t buf_size,
+    size_t *nrecv)
+{
+	*nrecv = 0;
+	return EOK;
 }
 
@@ -167,9 +169,10 @@
 		}
 		
-		ssize_t rc = rb->receive(rb->client_data, rb->buffer + rb->in, free);
-		if (rc <= 0)
+		size_t nrecv;
+		int rc = rb->receive(rb->client_data, rb->buffer + rb->in, free, &nrecv);
+		if (rc != EOK)
 			return rc;
 		
-		rb->in = rc;
+		rb->in = nrecv;
 	}
 	
@@ -180,21 +183,24 @@
 }
 
-ssize_t recv_buffer(receive_buffer_t *rb, char *buf, size_t buf_size)
-{
-	/* Flush any buffered data*/
+int recv_buffer(receive_buffer_t *rb, char *buf, size_t buf_size,
+    size_t *nrecv)
+{
+	/* Flush any buffered data */
 	if (rb->out != rb->in) {
 		size_t size = min(rb->in - rb->out, buf_size);
 		memcpy(buf, rb->buffer + rb->out, size);
 		rb->out += size;
-		return size;
-	}
-	
-	return rb->receive(rb->client_data, buf, buf_size);
+		*nrecv = size;
+		return EOK;
+	}
+	
+	return rb->receive(rb->client_data, buf, buf_size, nrecv);
 }
 
 /** Receive a character and if it is c, discard it from input buffer
- * @return number of characters discarded (0 or 1) or negative error code
- */
-ssize_t recv_discard(receive_buffer_t *rb, char discard)
+ * @param ndisc Place to store number of characters discarded
+ * @return EOK or error code
+ */
+int recv_discard(receive_buffer_t *rb, char discard, size_t *ndisc)
 {
 	char c = 0;
@@ -202,34 +208,39 @@
 	if (rc != EOK)
 		return rc;
-	if (c != discard)
-		return 0;
+	if (c != discard) {
+		*ndisc = 0;
+		return EOK;
+	}
 	rc = recv_char(rb, &c, true);
 	if (rc != EOK)
 		return rc;
-	return 1;
+	*ndisc = 1;
+	return EOK;
 }
 
 /** Receive a prefix of constant string discard and return number of bytes read
- * @return number of characters discarded or negative error code
- */
-ssize_t recv_discard_str(receive_buffer_t *rb, const char *discard)
+ * @param ndisc Place to store number of characters discarded
+ * @return EOK or error code
+ */
+int recv_discard_str(receive_buffer_t *rb, const char *discard, size_t *ndisc)
 {
 	size_t discarded = 0;
 	while (*discard) {
-		ssize_t rc = recv_discard(rb, *discard);
-		if (rc < 0)
-			return rc;
-		if (rc == 0)
+		size_t nd;
+		int rc = recv_discard(rb, *discard, &nd);
+		if (rc != EOK)
+			return rc;
+		if (nd == 0)
 			break;
-		discarded++;
+		discarded += nd;
 		discard++;
 	}
-	return discarded;
-}
-
-ssize_t recv_while(receive_buffer_t *rb, char_class_func_t class)
-{
-	size_t received = 0;
-	
+
+	*ndisc = discarded;
+	return EOK;
+}
+
+int recv_while(receive_buffer_t *rb, char_class_func_t class)
+{
 	while (true) {
 		char c = 0;
@@ -244,17 +255,16 @@
 		if (rc != EOK)
 			return rc;
-		
-		received++;
-	}
-	
-	return received;
+	}
+	
+	return EOK;
 }
 
 /** Receive an end of line, either CR, LF, CRLF or LFCR
  *
- * @return number of bytes read (0 if no newline is present in the stream)
- *         or negative error code
- */
-ssize_t recv_eol(receive_buffer_t *rb)
+ * @param nrecv Place to store number of bytes received (zero if
+ *              no newline is present in the stream)
+ * @return EOK on success or error code
+ */
+int recv_eol(receive_buffer_t *rb, size_t *nrecv)
 {
 	char c = 0;
@@ -263,6 +273,8 @@
 		return rc;
 	
-	if (c != '\r' && c != '\n')
-		return 0;
+	if (c != '\r' && c != '\n') {
+		*nrecv = 0;
+		return EOK;
+	}
 	
 	rc = recv_char(rb, &c, true);
@@ -270,15 +282,18 @@
 		return rc;
 	
-	ssize_t rc2 = recv_discard(rb, (c == '\r' ? '\n' : '\r'));
-	if (rc2 < 0)
-		return rc2;
-	
-	return 1 + rc2;
+	size_t nr;
+	rc = recv_discard(rb, (c == '\r' ? '\n' : '\r'), &nr);
+	if (rc != EOK)
+		return rc;
+	
+	*nrecv = 1 + nr;
+	return EOK;
 }
 
 /* Receive a single line */
-ssize_t recv_line(receive_buffer_t *rb, char *line, size_t size)
+int recv_line(receive_buffer_t *rb, char *line, size_t size, size_t *nrecv)
 {
 	size_t written = 0;
+	size_t nr;
 	
 	while (written < size) {
@@ -288,12 +303,19 @@
 			return rc;
 		if (c == '\n') {
-			recv_discard(rb, '\r');
+			rc = recv_discard(rb, '\r', &nr);
+			if (rc != EOK)
+				return rc;
+
 			line[written++] = 0;
-			return written;
+			*nrecv = written;
+			return EOK;
 		}
 		else if (c == '\r') {
-			recv_discard(rb, '\n');
+			rc = recv_discard(rb, '\n', &nr);
+			if (rc != EOK)
+				return rc;
 			line[written++] = 0;
-			return written;
+			*nrecv = written;
+			return EOK;
 		}
 		line[written++] = c;
