diff options
author | Andreas Schneider <asn@cryptomilk.org> | 2018-08-29 18:41:15 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2018-08-29 19:04:44 +0200 |
commit | 247983e9820fd264cb5a59c14cc12846c028bd08 (patch) | |
tree | d29b27aadcab16aa587df64c1972266bec994267 /src | |
parent | f0e99961b6d04b6fc7d4054a6c111223d8ff2894 (diff) | |
download | libssh-247983e9820fd264cb5a59c14cc12846c028bd08.tar.gz libssh-247983e9820fd264cb5a59c14cc12846c028bd08.tar.xz libssh-247983e9820fd264cb5a59c14cc12846c028bd08.zip |
misc: Add strndup implementation if not provides by the OS
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/misc.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -1085,4 +1085,25 @@ void explicit_bzero(void *s, size_t n) } #endif /* !HAVE_EXPLICIT_BZERO */ +#if !defined(HAVE_STRNDUP) +char *strndup(const char *s, size_t n) +{ + char *x = NULL; + + if (n + 1 < n) { + return NULL; + } + + x = malloc(n + 1); + if (x == NULL) { + return NULL; + } + + memcpy(x, s, n); + x[n] = '\0'; + + return x; +} +#endif /* ! HAVE_STRNDUP */ + /** @} */ |