xref: /csrg-svn/lib/libc/string/strxfrm.c (revision 42172)
1*42172Sbostic /*-
2*42172Sbostic  * Copyright (c) 1990 The Regents of the University of California.
3*42172Sbostic  * All rights reserved.
4*42172Sbostic  *
5*42172Sbostic  * This code is derived from software contributed to Berkeley by
6*42172Sbostic  * Chris Torek.
7*42172Sbostic  *
8*42172Sbostic  * %sccs.include.redist.c%
9*42172Sbostic  */
10*42172Sbostic 
11*42172Sbostic #if defined(LIBC_SCCS) && !defined(lint)
12*42172Sbostic static char sccsid[] = "@(#)strxfrm.c	5.1 (Berkeley) 05/17/90";
13*42172Sbostic #endif /* LIBC_SCCS and not lint */
14*42172Sbostic 
15*42172Sbostic #include <sys/stdc.h>
16*42172Sbostic #include <string.h>
17*42172Sbostic 
18*42172Sbostic /*
19*42172Sbostic  * Transform src, storing the result in dst, such that
20*42172Sbostic  * strcmp() on transformed strings returns what strcoll()
21*42172Sbostic  * on the original untransformed strings would return.
22*42172Sbostic  */
23*42172Sbostic size_t
24*42172Sbostic strxfrm(dst, src, n)
25*42172Sbostic 	register char *dst;
26*42172Sbostic 	register const char *src;
27*42172Sbostic 	register size_t n;
28*42172Sbostic {
29*42172Sbostic 	register size_t r = 0;
30*42172Sbostic 	register int c;
31*42172Sbostic 
32*42172Sbostic 	/*
33*42172Sbostic 	 * Since locales are unimplemented, this is just a copy.
34*42172Sbostic 	 */
35*42172Sbostic 	if (n != 0) {
36*42172Sbostic 		while ((c = *src++) != 0) {
37*42172Sbostic 			r++;
38*42172Sbostic 			if (--n == 0) {
39*42172Sbostic 				while (*src++ != 0)
40*42172Sbostic 					r++;
41*42172Sbostic 				break;
42*42172Sbostic 			}
43*42172Sbostic 			*dst++ = c;
44*42172Sbostic 		}
45*42172Sbostic 		*dst = 0;
46*42172Sbostic 	}
47*42172Sbostic 	return (r);
48*42172Sbostic }
49