cpp: IFD: Use same logic for read and write failures