Revert r5532, r5536 and a piece of r5531. The use of strncat and strndup was correct, pstrcpy and pstrdup wasn't. I'll try to restore building on non-gnu OSes in a later commit.
Changed paths: