Patch contributed by Karn Kallio <tierpluspluslists@skami.org>. Committed by falsifian <jcook@cs.berkeley.edu>.