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