The exit condition below does not work: if (ret < 0) { set_errno(-ret); return ERROR; } else { return count; }