2 Answers
2

You're always writing out the full buffer, even if you've only read part of it, because the third argument to write is len (the length of the buffer) instead of ss (the number of bytes read). Your loop should look like this: