Upstream patch from haikuports by Josef Gajdusek