[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sorting in glib2



On Wed, 3 Sep 2003, Marc Matteo wrote:

> strxfrm behaves differently on OpenBSD than on whatever system this
> weirdness was though up (Linux I betcha).  Rather than messing with the
> buffers just use strlen instead.  Apps should sort on the full string
> now.

actually, our strxfrm is deficient.  the patch below should correct libc.  
i haven't tested it (not a glib2 user) but should be more standards 
conformant.

Index: lib/libc/string/strxfrm.c
===================================================================
RCS file: /cvs/src/lib/libc/string/strxfrm.c,v
retrieving revision 1.4
diff -u -r1.4 strxfrm.c
--- lib/libc/string/strxfrm.c	2003/06/11 21:08:16	1.4
+++ lib/libc/string/strxfrm.c	2003/09/04 00:17:01
@@ -44,23 +44,11 @@
 size_t
 strxfrm(char *dst, const char *src, size_t n)
 {
-	size_t r = 0;
-	int c;
 
 	/*
 	 * Since locales are unimplemented, this is just a copy.
 	 */
-	if (n != 0) {
-		while ((c = *src++) != 0) {
-			r++;
-			if (--n == 0) {
-				while (*src++ != 0)
-					r++;
-				break;
-			}
-			*dst++ = c;
-		}
-		*dst = 0;
-	}
-	return (r);
+	if (n == 0)
+		return (strlen(src));
+	return (strlcpy(dst, src, n));
 }

-- 
we don't run washington and no one really does