xref: /csrg-svn/lib/libc/string/strxfrm.c (revision 46144)
142172Sbostic /*-
242172Sbostic  * Copyright (c) 1990 The Regents of the University of California.
342172Sbostic  * All rights reserved.
442172Sbostic  *
542172Sbostic  * This code is derived from software contributed to Berkeley by
642172Sbostic  * Chris Torek.
742172Sbostic  *
842172Sbostic  * %sccs.include.redist.c%
942172Sbostic  */
1042172Sbostic 
1142172Sbostic #if defined(LIBC_SCCS) && !defined(lint)
12*46144Sbostic static char sccsid[] = "@(#)strxfrm.c	5.2 (Berkeley) 01/26/91";
1342172Sbostic #endif /* LIBC_SCCS and not lint */
1442172Sbostic 
15*46144Sbostic #include <sys/cdefs.h>
1642172Sbostic #include <string.h>
1742172Sbostic 
1842172Sbostic /*
1942172Sbostic  * Transform src, storing the result in dst, such that
2042172Sbostic  * strcmp() on transformed strings returns what strcoll()
2142172Sbostic  * on the original untransformed strings would return.
2242172Sbostic  */
2342172Sbostic size_t
2442172Sbostic strxfrm(dst, src, n)
2542172Sbostic 	register char *dst;
2642172Sbostic 	register const char *src;
2742172Sbostic 	register size_t n;
2842172Sbostic {
2942172Sbostic 	register size_t r = 0;
3042172Sbostic 	register int c;
3142172Sbostic 
3242172Sbostic 	/*
3342172Sbostic 	 * Since locales are unimplemented, this is just a copy.
3442172Sbostic 	 */
3542172Sbostic 	if (n != 0) {
3642172Sbostic 		while ((c = *src++) != 0) {
3742172Sbostic 			r++;
3842172Sbostic 			if (--n == 0) {
3942172Sbostic 				while (*src++ != 0)
4042172Sbostic 					r++;
4142172Sbostic 				break;
4242172Sbostic 			}
4342172Sbostic 			*dst++ = c;
4442172Sbostic 		}
4542172Sbostic 		*dst = 0;
4642172Sbostic 	}
4742172Sbostic 	return (r);
4842172Sbostic }
49