Skip to contentSkip to conversation

compress: Change compress_write() to take buffer as const void *

PATCH Applied Richard Fitzgerald 1 participant 2 messages Feb 10, 2013 – Feb 22, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 2/14 compress: Change compress_write() to take buffer as const void *

The input buffer to compress_write() should be const, and is better defined as void * so the caller doesn't have to cast.

compress.c +4 -3
index 19b9366..ee11988 100644
@@ -299,11 +299,12 @@ int compress_get_tstamp(struct compress *compress,
 	return 0;
 }
 
-int compress_write(struct compress *compress, char *buf, unsigned int size)
+int compress_write(struct compress *compress, const void *buf, unsigned int size)
 {
 	struct snd_compr_avail avail;
 	struct pollfd fds;
 	int to_write, written, total = 0, ret;
+	const char* cbuf = buf;
 
 	if (!(compress->flags & COMPRESS_IN))
 		return oops(compress, -EINVAL, "Invalid flag set");
@@ -343,12 +344,12 @@ int compress_write(struct compress *compress, char *buf, unsigned int size)
 			to_write =  avail.avail;
 		else
 			to_write = size;
-		written = write(compress->fd, buf, to_write);
+		written = write(compress->fd, cbuf, to_write);
 		if (written < 0)
 			return oops(compress, errno, "write failed!\n");
 
 		size -= written;
-		buf += written;
+		cbuf += written;
 		total += written;
 	}
 	return total;
include/tinycompress/tinycompress.h +1 -1
index 8a98527..e285bd4 100644
@@ -125,7 +125,7 @@ int compress_get_tstamp(struct compress *compress,
  * @buf: pointer to data
  * @size: number of bytes to be written
  */
-int compress_write(struct compress *compress, char *buf, unsigned int size);
+int compress_write(struct compress *compress, const void *buf, unsigned int size);
 
 /*
  * compress_read: read data from the compress stream
Signature · 1 line
1.7.2.5
#1 lore raw

The input buffer to compress_write() should be const, and is better defined as void * so the caller doesn't have to cast.

---
 compress.c                          |    7 ++++---
 include/tinycompress/tinycompress.h |    2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)
compress.c +4 -3
index 01fb3f0..5429754 100644
@@ -312,11 +312,12 @@ int compress_get_tstamp(struct compress *compress,
 	return 0;
 }
 
-int compress_write(struct compress *compress, char *buf, unsigned int size)
+int compress_write(struct compress *compress, const void *buf, unsigned int size)
 {
 	struct snd_compr_avail avail;
 	struct pollfd fds;
 	int to_write, written, total = 0, ret;
+	const char* cbuf = buf;
 
 	if (!(compress->flags & COMPRESS_IN))
 		return oops(compress, -EINVAL, "Invalid flag set");
@@ -355,12 +356,12 @@ int compress_write(struct compress *compress, char *buf, unsigned int size)
 			to_write =  avail.avail;
 		else
 			to_write = size;
-		written = write(compress->fd, buf, to_write);
+		written = write(compress->fd, cbuf, to_write);
 		if (written < 0)
 			return oops(compress, errno, "write failed!");
 
 		size -= written;
-		buf += written;
+		cbuf += written;
 		total += written;
 	}
 	return total;
include/tinycompress/tinycompress.h +1 -1
index b1fbc65..49c0ff2 100644
@@ -126,7 +126,7 @@ int compress_get_tstamp(struct compress *compress,
  * @buf: pointer to data
  * @size: number of bytes to be written
  */
-int compress_write(struct compress *compress, char *buf, unsigned int size);
+int compress_write(struct compress *compress, const void *buf, unsigned int size);
 
 /*
  * compress_read: read data from the compress stream
Signature · 1 line
1.7.2.5