Rebased against ksh from OpenBSD 5.5.