changeset 64:83ae914a583a HEAD

added t_strdup_noconst() which can be used instead of (char *) t_strdup(). Removed several castings that removed the const qualifier.
author Timo Sirainen <tss@iki.fi>
date Wed, 28 Aug 2002 07:54:23 +0300
parents 8740373ee20e
children 168e0bd616b6
files src/auth/auth-digest-md5.c src/auth/cookie.c src/auth/userinfo-passwd.c src/auth/userinfo-shadow.c src/imap/cmd-fetch.c src/imap/commands.c src/lib/network.c src/lib/strfuncs.c src/lib/strfuncs.h src/login/client-authenticate.c
diffstat 10 files changed, 19 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/auth/auth-digest-md5.c	Wed Aug 28 07:43:06 2002 +0300
+++ b/src/auth/auth-digest-md5.c	Wed Aug 28 07:54:23 2002 +0300
@@ -465,7 +465,7 @@
 
 	failed = FALSE;
 
-	copy = (char *) t_strndup(data, size);
+	copy = t_strdup_noconst(t_strndup(data, size));
 	while (*copy != '\0') {
 		if (parse_next(&copy, &key, &value)) {
 			if (!auth_handle_response(auth, key, value, error)) {
--- a/src/auth/cookie.c	Wed Aug 28 07:43:06 2002 +0300
+++ b/src/auth/cookie.c	Wed Aug 28 07:54:23 2002 +0300
@@ -48,7 +48,8 @@
 	int i, ret;
 
 	for (i = 0; i < AUTH_COOKIE_SIZE; i++) {
-		ret = ((unsigned char *) p1)[i] - ((unsigned char *) p2)[i];
+		ret = ((const unsigned char *) p1)[i] -
+			((const unsigned char *) p2)[i];
 		if (ret != 0)
 			return ret;
 	}
--- a/src/auth/userinfo-passwd.c	Wed Aug 28 07:43:06 2002 +0300
+++ b/src/auth/userinfo-passwd.c	Wed Aug 28 07:54:23 2002 +0300
@@ -42,7 +42,7 @@
 		return FALSE;
 
 	/* check if the password is valid */
-        passdup = (char *) t_strdup(password);
+        passdup = t_strdup_noconst(password);
 	result = strcmp(crypt(passdup, pw->pw_passwd), pw->pw_passwd) == 0;
 
 	/* clear the passwords from memory */
--- a/src/auth/userinfo-shadow.c	Wed Aug 28 07:43:06 2002 +0300
+++ b/src/auth/userinfo-shadow.c	Wed Aug 28 07:54:23 2002 +0300
@@ -32,7 +32,7 @@
 		return FALSE;
 
 	/* check if the password is valid */
-        passdup = (char *) t_strdup(password);
+        passdup = t_strdup_noconst(password);
 	result = strcmp(crypt(passdup, spw->sp_pwdp), spw->sp_pwdp) == 0;
 
 	/* clear the passwords from memory */
--- a/src/imap/cmd-fetch.c	Wed Aug 28 07:43:06 2002 +0300
+++ b/src/imap/cmd-fetch.c	Wed Aug 28 07:54:23 2002 +0300
@@ -35,7 +35,7 @@
 	body = t_new(MailFetchBodyData, 1);
 	body->peek = peek;
 
-	p = (char *) t_strdup(item);
+	p = t_strdup_noconst(item);
 
 	/* read section */
 	body->section = p;
--- a/src/imap/commands.c	Wed Aug 28 07:43:06 2002 +0300
+++ b/src/imap/commands.c	Wed Aug 28 07:54:23 2002 +0300
@@ -6,7 +6,7 @@
 ClientCommandFunc client_command_find(const char *name)
 {
 	/* keep the command uppercased */
-	name = str_ucase((char *) t_strdup(name));
+	name = str_ucase(t_strdup_noconst(name));
 
 	switch (*name) {
 	case 'A':
--- a/src/lib/network.c	Wed Aug 28 07:43:06 2002 +0300
+++ b/src/lib/network.c	Wed Aug 28 07:54:23 2002 +0300
@@ -369,7 +369,7 @@
 	i_assert(data != NULL);
 	i_assert(len <= INT_MAX);
 
-	ret = send(fd, (void *) data, len, 0);
+	ret = send(fd, data, len, 0);
 	if (ret == -1 && (errno == EINTR || errno == EPIPE || errno == EAGAIN))
                 return 0;
 
--- a/src/lib/strfuncs.c	Wed Aug 28 07:43:06 2002 +0300
+++ b/src/lib/strfuncs.c	Wed Aug 28 07:54:23 2002 +0300
@@ -510,6 +510,14 @@
         STRDUP_CORE(t_malloc(len), str);
 }
 
+char *t_strdup_noconst(const char *str)
+{
+	if (str == NULL)
+                return NULL;
+
+        STRDUP_CORE(t_malloc(len), str);
+}
+
 int *p_intarrdup(Pool pool, const int *arr)
 {
 	if (arr == NULL)
@@ -847,7 +855,7 @@
 
 char *const *t_strsplit(const char *data, const char *separators)
 {
-        const char **array;
+        char **array;
 	char *str;
         int alloc_len, len;
 
--- a/src/lib/strfuncs.h	Wed Aug 28 07:43:06 2002 +0300
+++ b/src/lib/strfuncs.h	Wed Aug 28 07:54:23 2002 +0300
@@ -31,6 +31,7 @@
 
 /* same with temporary memory allocations: */
 const char *t_strdup(const char *str);
+char *t_strdup_noconst(const char *str);
 const char *t_strdup_empty(const char *str); /* return NULL if str = "" */
 const char *t_strdup_until(const char *start, const char *end); /* *end isn't included */
 const char *t_strndup(const char *str, unsigned int max_chars);
--- a/src/login/client-authenticate.c	Wed Aug 28 07:43:06 2002 +0300
+++ b/src/login/client-authenticate.c	Wed Aug 28 07:54:23 2002 +0300
@@ -144,7 +144,7 @@
 		    reply_data[reply_data_size-1] == '\0') {
 			client_auth_abort(client, t_strconcat(
 				"NO Authentication failed: ",
-				(char *) reply_data, NULL));
+				(const char *) reply_data, NULL));
 		} else {
 			/* default error message */
 			client_auth_abort(client, NULL);