Incorporated from BSD 4.4-Lite.