fix check for 0 bytes written