provided by Martin Laubach (with a few modifications to work under NetBSD-1.3.3 as well as -current) -- thanks!