Patch submitted by Chris Pinnock <C.J.E.Pinnock@qmw.ac.uk> in PR 11849, adjusted for NetBSD-current by me.