Simplify copy and copyn, using str[n]dup

Add gnulib strndup module for platforms that lack it (we already
assumed strdup).