diff options
author | Marcus Huderle <huderlem@gmail.com> | 2017-12-27 16:22:00 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-27 16:22:00 -0600 |
commit | 6b611a3046a694d3972f2aa4df90d3ef78801217 (patch) | |
tree | 05f295c00cbbc1d5987a05da37e746fb841d4d83 /libc/string/strxfrm.c | |
parent | 58c860d6c48324eba66dd19540db5584d832cf58 (diff) | |
parent | d88495e3f4061a411e654c7307aa94ac8a98c94b (diff) |
Merge pull request #13 from ProjectRevoTPP/libc
add libc building to agbcc.
Diffstat (limited to 'libc/string/strxfrm.c')
-rw-r--r-- | libc/string/strxfrm.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/libc/string/strxfrm.c b/libc/string/strxfrm.c new file mode 100644 index 0000000..65ed4f1 --- /dev/null +++ b/libc/string/strxfrm.c @@ -0,0 +1,75 @@ +/* +FUNCTION + <<strxfrm>>---transform string + +INDEX + strxfrm + +ANSI_SYNOPSIS + #include <string.h> + size_t strxfrm(char *<[s1]>, const char *<[s2]>, size_t <[n]>); + +TRAD_SYNOPSIS + #include <string.h> + size_t strxfrm(<[s1]>, <[s2]>, <[n]>); + char *<[s1]>; + char *<[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. + + With a C locale, this function just copies. + +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 +_DEFUN (strxfrm, (s1, s2, n), + char *s1 _AND + _CONST char *s2 _AND + 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; +} |