fix tests on bsd
merge of '43ad1fd9d25d2b69da978f778fc750e3c9adafae'
     and '91a7ca8ff1125939ae5e7ca6bf9168b858abc3db'