changeset 167:1167cd06b475

Use stdint.h values
author David Demelier <markand@malikania.fr>
date Thu, 25 Oct 2012 12:57:58 +0200
parents 7f214f26a4c0
children a89ff602b30f
files pack.c pack.h
diffstat 2 files changed, 19 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/pack.c	Mon Sep 24 23:04:25 2012 +0200
+++ b/pack.c	Thu Oct 25 12:57:58 2012 +0200
@@ -55,7 +55,7 @@
 	/* for writing */
 	int		nelem;		/* number of element */
 	int		size;		/* size of elements */
-	long		value;		/* direct value */
+	uint64_t	value;		/* direct value */
 	char *		array;		/* array of values */
 
 	/* for reading */
@@ -91,16 +91,16 @@
 #define TOKSIZE(tok, size) do {						\
 	switch (tok) {							\
 	case 'c':							\
-		size = sizeof (char);					\
+		size = sizeof (uint8_t);				\
 		break;							\
 	case 's':							\
-		size = sizeof (short);					\
+		size = sizeof (uint16_t);				\
 		break;							\
 	case 'i':							\
-		size = sizeof (int);					\
+		size = sizeof (uint32_t);				\
 		break;							\
 	case 'l':							\
-		size = sizeof (long);					\
+		size = sizeof (uint64_t);				\
 		break;							\
 	default:							\
 		size = 0;						\
@@ -110,20 +110,20 @@
 
 #define TOKGETARG(serv, tok, val, ap) do {				\
 	if ((val)->nelem == 1 && serv == writeto) {			\
-		long item;						\
+		uint64_t item;						\
 		switch (tok) {						\
 		case 'c': case 's': case 'i':				\
 			item = va_arg(ap, int);				\
 			break;						\
 		case 'l':						\
-			item = va_arg(ap, long);			\
+			item = va_arg(ap, uint64_t);			\
 			break;						\
 		default:						\
 			item = 0;					\
 			break;						\
 		}							\
 									\
-		memset(&(val)->value, 0, sizeof (long));		\
+		memset(&(val)->value, 0, sizeof (uint64_t));		\
 		memcpy(&(val)->value, &item, (val)->size);		\
 		(val)->array = (char *)&(val)->value;			\
 	} else { /* read is always a pointer */				\
@@ -135,11 +135,11 @@
 #define GETCONV(ed, size, conv) do {					\
 	if (ed != PACK_HOST_BYTEORDER) {				\
 		switch ((size)) {					\
-		case (sizeof (short)):					\
+		case (sizeof (uint16_t)):				\
 			conv = conv16; break;				\
-		case (sizeof (int)):					\
+		case (sizeof (uint32_t)):				\
 			conv = conv32; break;				\
-		case (sizeof (long)):					\
+		case (sizeof (uint64_t)):				\
 			conv = conv64; break;				\
 		default:						\
 			conv = NULL;					\
@@ -151,19 +151,19 @@
 static void
 conv16(void *item)
 {
-	*(short *)item = pack_swap16(*(short *)item);
+	*(uint16_t *)item = pack_swap16(*(uint16_t *)item);
 }
 
 static void
 conv32(void *item)
 {
-	*(int *)item = pack_swap32(*(int *)item);
+	*(uint32_t *)item = pack_swap32(*(uint32_t *)item);
 }
 
 static void
 conv64(void *item)
 {
-	*(long *)item = pack_swap64(*(long *)item);
+	*(uint64_t *)item = pack_swap64(*(uint64_t *)item);
 }
 
 /*
@@ -176,7 +176,8 @@
 {
 	void (*conv)(void *);
 	int i;
-	long item, nbytes = 0;
+	uint64_t item;
+	long nbytes = 0;
 
 	/* Get converter */
 	GETCONV(sc->endian, val->size, conv);
@@ -225,7 +226,8 @@
 {
 	void (*conv)(void *);
 	int i, oktoread;
-	long item, nbytes = 0;
+	uint64_t item;
+	long nbytes = 0;
 
 	/* Get converter */
 	GETCONV(sc->endian, val->size, conv);
--- a/pack.h	Mon Sep 24 23:04:25 2012 +0200
+++ b/pack.h	Thu Oct 25 12:57:58 2012 +0200
@@ -20,6 +20,7 @@
 #define _PACK_H_
 
 #include <stdarg.h>
+#include <stdint.h>
 
 #define PACK_LE		1234
 #define PACK_BE		4321