diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-02-15 17:40:40 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-02-15 17:40:40 +0000 |
commit | a896ca2a8c617e5e00ffd5fc9e69331ad754e5b3 (patch) | |
tree | f49a8382b9999b5aa00c0885eedd5c5c3a233e55 /src/libstddjb/str_strn.c | |
parent | 00c9cb1b22cc17c4db573e0e613a5f116ff0092e (diff) | |
download | skalibs-a896ca2a8c617e5e00ffd5fc9e69331ad754e5b3.tar.xz |
add arc4random_addrandom sysdep; next batch of types changes.
The library isn't supposed to be functional yet: there are
still a lot of type mismatches.
Diffstat (limited to 'src/libstddjb/str_strn.c')
-rw-r--r-- | src/libstddjb/str_strn.c | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/src/libstddjb/str_strn.c b/src/libstddjb/str_strn.c index 7c2e425..fef219b 100644 --- a/src/libstddjb/str_strn.c +++ b/src/libstddjb/str_strn.c @@ -1,36 +1,16 @@ /* ISC license. */ -#include <skalibs/config.h> -#include <skalibs/bytestr.h> - -#ifdef SKALIBS_FLAG_REPLACE_LIBC - -/* Very naive implementation, but it's small. */ - -unsigned int str_strn (char const *haystack, unsigned int hlen, char const *needle, unsigned int nlen) -{ - register unsigned int i = 0 ; - if (!nlen) return 0 ; - if (hlen < nlen) return hlen ; - hlen -= nlen ; - for (; i <= hlen ; i++) - if (!byte_diff(haystack+i, nlen, needle)) return i ; - return hlen+nlen ; -} - -#else - +#include <sys/types.h> #include <string.h> +#include <skalibs/bytestr.h> -unsigned int str_strn (char const *haystack, unsigned int hlen, char const *needle, unsigned int nlen) +size_t str_strn (char const *haystack, size_t hlen, char const *needle, size_t nlen) { char haystack2[hlen+1] ; char needle2[nlen+1] ; - register char *p ; + char *p ; byte_copy(haystack2, hlen, haystack) ; haystack2[hlen] = 0 ; byte_copy(needle2, nlen, needle) ; needle2[nlen] = 0 ; p = strstr(haystack2, needle2) ; return p ? p - haystack2 : hlen ; } - -#endif |