Rebased against ksh from OpenBSD 5.4.