Check for the return value of write being -1 before adding.