Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6536 serge 1
/*
2
FUNCTION
3
	<>---transform string
4
 
5
INDEX
6
	strxfrm
7
 
8
ANSI_SYNOPSIS
9
	#include 
10
	size_t strxfrm(char *restrict <[s1]>, const char *restrict <[s2]>,
11
                       size_t <[n]>);
12
 
13
TRAD_SYNOPSIS
14
	#include 
15
	size_t strxfrm(<[s1]>, <[s2]>, <[n]>);
16
	char *<[s1]>;
17
	char *<[s2]>;
18
	size_t <[n]>;
19
 
20
DESCRIPTION
21
	This function transforms the string pointed to by <[s2]> and
22
	places the resulting string into the array pointed to by
23
	<[s1]>. The transformation is such that if the <>
24
	function is applied to the two transformed strings, it returns
25
	a value greater than, equal to, or less than zero,
26
	correspoinding to the result of a <> function applied
27
	to the same two original strings.
28
 
29
	No more than <[n]> characters are placed into the resulting
30
	array pointed to by <[s1]>, including the terminating null
31
	character. If <[n]> is zero, <[s1]> may be a null pointer. If
32
	copying takes place between objects that overlap, the behavior
33
	is undefined.
34
 
35
	With a C locale, this function just copies.
36
 
37
RETURNS
38
	The <> 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
<> is ANSI C.
45
 
46
<> requires no supporting OS subroutines.
47
 
48
QUICKREF
49
	strxfrm ansi pure
50
*/
51
 
52
#include 
53
 
54
size_t
55
_DEFUN (strxfrm, (s1, s2, n),
56
	char *__restrict s1 _AND
57
	_CONST char *__restrict s2 _AND
58
	size_t n)
59
{
60
  size_t res;
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
}