Patches provided by Joel Baker in PR 22365, verified by myself.
Changed to conform to NetBSD's new RCS Id convention.