[dovecot-cvs] dovecot/src/lib buffer.c, 1.18, 1.19 buffer.h, 1.10, 1.11

cras at dovecot.org cras at dovecot.org
Sun Oct 3 19:30:20 EEST 2004


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv20833

Modified Files:
	buffer.c buffer.h 
Log Message:
Added buffer_insert_zero()



Index: buffer.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/buffer.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- buffer.c	12 Sep 2004 13:00:13 -0000	1.18
+++ buffer.c	3 Oct 2004 16:30:18 -0000	1.19
@@ -194,28 +194,12 @@
 		     const void *data, size_t data_size)
 {
 	struct real_buffer *buf = (struct real_buffer *)_buf;
-	size_t move_size, size;
+	size_t size;
 
 	if (pos >= buf->used)
 		return buffer_write(_buf, pos, data, data_size);
 
-	/* move_size == number of bytes we have to move forward to make space */
-	move_size = buf->used - pos;
-
-	/* size == number of bytes we want to modify after pos */
-	if (data_size < (size_t)-1 - move_size)
-		size = data_size + move_size;
-	else
-		size = (size_t)-1;
-
-	if (!buffer_check_limits(buf, pos, &size, TRUE))
-		return 0;
-
-	i_assert(size >= move_size);
-	size -= move_size;
-	/* size == number of bytes we actually inserted. data_size usually. */
-
-	memmove(buf->w_buffer + pos + size, buf->w_buffer + pos, move_size);
+	size = buffer_copy(_buf, pos + data_size, _buf, pos, (size_t)-1);
 	memcpy(buf->w_buffer + pos, data, size);
 	return size;
 }
@@ -260,6 +244,19 @@
 	return buffer_write_zero(buf, buf->used, data_size);
 }
 
+size_t buffer_insert_zero(buffer_t *_buf, size_t pos, size_t data_size)
+{
+	struct real_buffer *buf = (struct real_buffer *)_buf;
+	size_t size;
+
+	if (pos >= buf->used)
+		return buffer_write_zero(_buf, pos, data_size);
+
+	size = buffer_copy(_buf, pos + data_size, _buf, pos, (size_t)-1);
+	memset(buf->w_buffer + pos, 0, size);
+	return size;
+}
+
 size_t buffer_copy(buffer_t *_dest, size_t dest_pos,
 		   const buffer_t *_src, size_t src_pos, size_t copy_size)
 {

Index: buffer.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/buffer.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- buffer.h	12 Sep 2004 13:00:13 -0000	1.10
+++ buffer.h	3 Oct 2004 16:30:18 -0000	1.11
@@ -51,6 +51,7 @@
 /* Fill buffer with zero bytes. */
 size_t buffer_write_zero(buffer_t *buf, size_t pos, size_t data_size);
 size_t buffer_append_zero(buffer_t *buf, size_t data_size);
+size_t buffer_insert_zero(buffer_t *buf, size_t pos, size_t data_size);
 
 /* Copy data from buffer to another. The buffers may be same in which case
    it's internal copying, possibly with overlapping positions (ie. memmove()



More information about the dovecot-cvs mailing list