Code from Learning C The Hard Way -- for portability