PR: 6829 Submitted by: Josh Gilliam <josh@quick.net>
Obtained from: cyclic.com
and non-unix code has been left out.