1 /*
2 Copyright (c) 2016 Corinna Vinschen <corinna@vinschen.de>
3 */
4 /*
5 FUNCTION
6 <<strxfrm_l>>---transform string
7
8 INDEX
9 strxfrm_l
10
11 SYNOPSIS
12 #include <string.h>
13 size_t strxfrm_l(char *restrict <[s1]>, const char *restrict <[s2]>,
14 size_t <[n]>, locale_t <[locale]>);
15
16 DESCRIPTION
17 This function transforms the string pointed to by <[s2]> and
18 places the resulting string into the array pointed to by
19 <[s1]>. The transformation is such that if the <<strcmp>>
20 function is applied to the two transformed strings, it returns
21 a value greater than, equal to, or less than zero,
22 correspoinding to the result of a <<strcoll>> function applied
23 to the same two original strings.
24
25 No more than <[n]> characters are placed into the resulting
26 array pointed to by <[s1]>, including the terminating null
27 character. If <[n]> is zero, <[s1]> may be a null pointer. If
28 copying takes place between objects that overlap, the behavior
29 is undefined.
30
31 (NOT Cygwin:) The current implementation of <<strxfrm_l>> simply copies
32 the input and does not support any language-specific transformations.
33
34 If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the
35 behaviour is undefined.
36
37 RETURNS
38 The <<strxfrm_l>> function returns the length of the transformed string
39 (not including the terminating null character). If the value returned
40 is <[n]> or more, the contents of the array pointed to by
41 <[s1]> are indeterminate.
42
43 PORTABILITY
44 <<strxfrm_l>> is POSIX-1.2008.
45
46 <<strxfrm_l>> requires no supporting OS subroutines.
47
48 QUICKREF
49 strxfrm_l ansi pure
50 */
51
52 #define _DEFAULT_SOURCE
53 #include <string.h>
54
55 size_t
strxfrm_l(char * __restrict s1,const char * __restrict s2,size_t n,locale_t locale)56 strxfrm_l (char *__restrict s1, const char *__restrict s2, size_t n,
57 locale_t locale)
58 {
59 size_t res;
60 (void) locale;
61 res = 0;
62 while (n-- > 0)
63 {
64 if ((*s1++ = *s2++) != '\0')
65 ++res;
66 else
67 return res;
68 }
69 while (*s2)
70 {
71 ++s2;
72 ++res;
73 }
74
75 return res;
76 }
77