fix bug on FreeBSD and Mac OS X