File: strxfrm.c

package info (click to toggle)
picolibc 1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 31,616 kB
  • sloc: ansic: 312,308; asm: 22,739; perl: 2,414; sh: 1,619; python: 1,019; pascal: 329; exp: 287; makefile: 164; xml: 40; cpp: 10
file content (85 lines) | stat: -rw-r--r-- 2,382 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
Copyright (c) 1994 Cygnus Support.
All rights reserved.

Redistribution and use in source and binary forms are permitted
provided that the above copyright notice and this paragraph are
duplicated in all such forms and that any documentation,
and/or other materials related to such
distribution and use acknowledge that the software was developed
at Cygnus Support, Inc.  Cygnus Support, Inc. may not be used to
endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */
/*
FUNCTION
	<<strxfrm>>---transform string

INDEX
	strxfrm

SYNOPSIS
	#include <string.h>
	size_t strxfrm(char *restrict <[s1]>, const char *restrict <[s2]>,
                       size_t <[n]>);

DESCRIPTION
	This function transforms the string pointed to by <[s2]> and
	places the resulting string into the array pointed to by
	<[s1]>. The transformation is such that if the <<strcmp>>
	function is applied to the two transformed strings, it returns
	a value greater than, equal to, or less than zero,
	correspoinding to the result of a <<strcoll>> function applied
	to the same two original strings.

	No more than <[n]> characters are placed into the resulting
	array pointed to by <[s1]>, including the terminating null
	character. If <[n]> is zero, <[s1]> may be a null pointer. If
	copying takes place between objects that overlap, the behavior
	is undefined.

	(NOT Cygwin:) The current implementation of <<strxfrm>> simply copies
	the input and does not support any language-specific transformations.

RETURNS
	The <<strxfrm>> function returns the length of the transformed string
	(not including the terminating null character). If the value returned
	is <[n]> or more, the contents of the array pointed to by
	<[s1]> are indeterminate.

PORTABILITY
<<strxfrm>> is ANSI C.

<<strxfrm>> requires no supporting OS subroutines.

QUICKREF
	strxfrm ansi pure
*/

#include <string.h>

size_t
strxfrm (char *__restrict s1,
	const char *__restrict s2,
	size_t n)
{
  size_t res;
  res = 0;
  while (n-- > 0)
    {
      if ((*s1++ = *s2++) != '\0')
        ++res;
      else
        return res;
    }
  while (*s2)
    {
      ++s2;
      ++res;
    }

  return res;
}