[dovecot-cvs] dovecot/src/lib hex-binary.c, 1.6, 1.7 hex-binary.h, 1.6, 1.7

cras at dovecot.org cras at dovecot.org
Wed Jul 28 18:21:30 EEST 2004


Update of /home/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv28518

Modified Files:
	hex-binary.c hex-binary.h 
Log Message:
Added binary_to_hex_ucase()



Index: hex-binary.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/hex-binary.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- hex-binary.c	26 Aug 2003 21:18:16 -0000	1.6
+++ hex-binary.c	28 Jul 2004 15:21:28 -0000	1.7
@@ -4,27 +4,39 @@
 #include "buffer.h"
 #include "hex-binary.h"
 
-const char *binary_to_hex(const unsigned char *data, size_t size)
+static const char *
+binary_to_hex_case(const unsigned char *data, size_t size, int ucase)
 {
-	char *buf, *p;
+	char *buf, *p, base_char;
 	size_t i;
 	int value;
 
 	/* @UNSAFE */
+	base_char = ucase ? 'A' : 'a';
 
 	buf = p = t_malloc(size * 2 + 1);
 	for (i = 0; i < size; i++) {
 		value = data[i] >> 4;
-		*p++ = value < 10 ? value + '0' : value - 10 + 'a';
+		*p++ = value < 10 ? value + '0' : value - 10 + base_char;
 
 		value = data[i] & 0x0f;
-		*p++ = value < 10 ? value + '0' : value - 10 + 'a';
+		*p++ = value < 10 ? value + '0' : value - 10 + base_char;
 	}
 
 	*p = '\0';
 	return buf;
 }
 
+const char *binary_to_hex(const unsigned char *data, size_t size)
+{
+	return binary_to_hex_case(data, size, FALSE);
+}
+
+const char *binary_to_hex_ucase(const unsigned char *data, size_t size)
+{
+	return binary_to_hex_case(data, size, TRUE);
+}
+
 int hex_to_binary(const char *data, buffer_t *dest)
 {
 	int value;

Index: hex-binary.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/hex-binary.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- hex-binary.h	5 Jan 2003 13:09:51 -0000	1.6
+++ hex-binary.h	28 Jul 2004 15:21:28 -0000	1.7
@@ -1,9 +1,9 @@
 #ifndef __HEX_BINARY_H
 #define __HEX_BINARY_H
 
-/* Convert binary to lowercased hex digits allocating return value from
-   data stack */
+/* Convert binary to hex digits allocating return value from data stack */
 const char *binary_to_hex(const unsigned char *data, size_t size);
+const char *binary_to_hex_ucase(const unsigned char *data, size_t size);
 
 /* Convert hex to binary. data and dest may point to same value.
    Returns TRUE if successful. Returns 1 if all ok, 0 if dest buffer got full



More information about the dovecot-cvs mailing list