Example from go9p to run on Plan 9. Lots of work to remove UNIX'isms.