[dovecot-cvs] dovecot/src/lib strfuncs.c,1.23,1.24 strfuncs.h,1.12,1.13

cras at procontrol.fi cras at procontrol.fi
Sun Dec 22 10:18:31 EET 2002


Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv13893/lib

Modified Files:
	strfuncs.c strfuncs.h 
Log Message:
t_strsplit() returns now const char **, which removes a few nasty casts.
Removed a few unneded functions and did some small cleanups.



Index: strfuncs.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/strfuncs.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -d -r1.23 -r1.24
--- strfuncs.c	22 Dec 2002 07:31:51 -0000	1.23
+++ strfuncs.c	22 Dec 2002 08:18:29 -0000	1.24
@@ -267,6 +267,8 @@
 		}
 	} while (str != NULL);
 
+	i_assert(pos < bufsize);
+
 	temp[pos] = '\0';
         *ret_len = pos+1;
         return temp;
@@ -466,45 +468,17 @@
 	*dest = '\0';
 }
 
-int strarray_length(char *const array[])
-{
-	int len;
-
-	len = 0;
-	while (*array) {
-		len++;
-                array++;
-	}
-        return len;
-}
-
-int strarray_find(char *const array[], const char *item)
-{
-	int index;
-
-	i_assert(item != NULL);
-
-	for (index = 0; *array != NULL; index++, array++) {
-		if (strcasecmp(*array, item) == 0)
-			return index;
-	}
-
-	return -1;
-}
-
-char *const *t_strsplit(const char *data, const char *separators)
+const char **t_strsplit(const char *data, const char *separators)
 {
-        char **array;
+        const char **array;
 	char *str;
         size_t alloc_len, len;
 
         i_assert(*separators != '\0');
 
-	len = strlen(data)+1;
-	str = t_malloc(len);
-	memcpy(str, data, len);
+	str = t_strdup_noconst(data);
 
-        alloc_len = 20;
+        alloc_len = 32;
         array = t_buffer_get(sizeof(const char *) * alloc_len);
 
 	array[0] = str; len = 1;
@@ -512,7 +486,7 @@
 		if (strchr(separators, *str) != NULL) {
 			/* separator found */
 			if (len+1 >= alloc_len) {
-                                alloc_len *= 2;
+                                alloc_len = nearest_power(alloc_len+1);
 				array = t_buffer_reget(array,
 						       sizeof(const char *) *
 						       alloc_len);
@@ -524,10 +498,12 @@
 
                 str++;
 	}
+
+	i_assert(len < alloc_len);
         array[len] = NULL;
 
 	t_buffer_alloc(sizeof(const char *) * (len+1));
-        return (char *const *) array;
+        return array;
 }
 
 const char *dec2str(uintmax_t number)
@@ -543,6 +519,7 @@
 		buffer[--pos] = (number % 10) + '0';
 		number /= 10;
 	} while (number != 0 && pos >= 0);
+
 	i_assert(pos >= 0);
 	return buffer + pos;
 }

Index: strfuncs.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/strfuncs.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- strfuncs.h	22 Dec 2002 07:06:16 -0000	1.12
+++ strfuncs.h	22 Dec 2002 08:18:29 -0000	1.13
@@ -51,13 +51,8 @@
 char *str_lcase(char *str);
 void str_remove_escapes(char *str);
 
-/* returns number of items in array */
-int strarray_length(char *const array[]);
-/* return index of item in array, or -1 if not found */
-int strarray_find(char *const array[], const char *item);
-
 /* seprators is an array of separator characters, not a separator string. */
-char *const *t_strsplit(const char *data, const char *separators);
+const char **t_strsplit(const char *data, const char *separators);
 
 const char *dec2str(uintmax_t number);
 




More information about the dovecot-cvs mailing list