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