Perhaps xstrndup() ...