diff options
Diffstat (limited to 'miniany/libc-freestanding.c')
-rw-r--r-- | miniany/libc-freestanding.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/miniany/libc-freestanding.c b/miniany/libc-freestanding.c index a68a0c5..67f10fb 100644 --- a/miniany/libc-freestanding.c +++ b/miniany/libc-freestanding.c @@ -30,6 +30,51 @@ int strcmp( char *s1, char *s2 ) return *s1 - *s2; } +int strlcpy( char *d, const char *s, int n ) +{ + int len = 0; + + while( len < n && s[len] != '\0' ) { + d[len] = s[len]; + len++; + } + d[len] = '\0'; + + while( s[len] != '\0' ) { + len++; + } + + if( len >= n ) { + d[n-1] = '\0'; + } + + return len; +} + +int strlcat( char *d, char *s, int n ) +{ + int len = 0; + char *ss = s; + char *dd = d; + + while( len < n && *dd != '\0' ) { + len++; + dd++; + } + + if( len == n ) { + return len + strlen( s ); + } + + while( len + 1 < n && ( *dd++ = *ss++ ) ) { + len++; + } + + *dd = '\0'; + + return len; +} + int memcmp( char *s1, char *s2, int n ) { while( n > 0 ) { |