Fix build on FreeBSD

Fix bugs introduced in dc066d5ceb9b364cbb334fc34d899e3b1b0803e7 and 3697313aebeec429b16163de78ea1949a3e801c3.