Replace strndup with malloc/strncpy, some compilers do not provide this function