xutil: Implement xstrndup without relying on strndup.