DragonFly BSD changes contributed by fgudin and extrudedaluminiu (see issue 181 at inferno-os.googlecode.com)