unix: make stream.c more DRY