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