source: trunk/libs/newlib/src/newlib/libc/string/strxfrm_l.c @ 543

Last change on this file since 543 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.8 KB
Line 
1/*
2FUNCTION
3        <<strxfrm_l>>---transform string
4
5INDEX
6        strxfrm_l
7
8SYNOPSIS
9        #include <string.h>
10        size_t strxfrm_l(char *restrict <[s1]>, const char *restrict <[s2]>,
11                       size_t <[n]>, locale_t <[locale]>);
12
13DESCRIPTION
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_l>> simply copies
29        the input and does not support any language-specific transformations.
30
31        If <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the
32        behaviour is undefined.
33
34RETURNS
35        The <<strxfrm_l>> function returns the length of the transformed string
36        (not including the terminating null character). If the value returned
37        is <[n]> or more, the contents of the array pointed to by
38        <[s1]> are indeterminate.
39
40PORTABILITY
41<<strxfrm_l>> is POSIX-1.2008.
42
43<<strxfrm_l>> requires no supporting OS subroutines.
44
45QUICKREF
46        strxfrm_l ansi pure
47*/
48
49#include <string.h>
50
51size_t
52strxfrm_l (char *__restrict s1, const char *__restrict s2, size_t n,
53           struct __locale_t *locale)
54{
55  size_t res;
56  res = 0;
57  while (n-- > 0)
58    {
59      if ((*s1++ = *s2++) != '\0')
60        ++res;
61      else
62        return res;
63    }
64  while (*s2)
65    {
66      ++s2;
67      ++res;
68    }
69
70  return res;
71}
Note: See TracBrowser for help on using the repository browser.