Based on a patch from Philip Prindeville. While at it, also refresh the patches. SVN-Revision: 30025
SVN-Revision: 30022