Copied verbatim from the standard library, I thought it was OK to leave it.