private strndup() implementation in case libc does not provide it
Change strdup() to strndup()