Implement `xstrdup`, `xstrndup` and `xmemdup`

Utility functions for copying memory to newly-allocated chunks. They either
succeed or exit the program.
Replace `strdup` calls by `xstrdup`