synchronous stream implementation in C