Il 21/02/2013 17:47, Andy Wingo ha scritto: >> > Doesn't it need to set errno to zero before calling full_read? > Not sure! If full_read requires that errno be 0 going in, then yes, we > should. Is this a requirement?
Hmm, I think usually errno is undefined for return values other than -1, so neither approach would work portably... I think you have to do ret = full_read (fd, cookie, sizeof cookie); if (ret < sizeof cookie && ret != -1) ret = 0; if (ret == sizeof cookie) ret = full_read (fd, SCM_BYTEVECTOR_CONTENTS (bv), SCM_BYTEVECTOR_LENGTH (bv)); if (ret < SCM_BYTEVECTOR_LENGTH (bv)) { int errno_save = errno; (void) close (fd); errno = errno_save; if (ret == -1) SCM_SYSERROR; scm_misc_error (FUNC_NAME, "file truncated while reading", SCM_EOL); } Paolo > Otherwise, full_read sets errno to 0 if it returns a length less than > the length we asked for, and we're OK in that case AFAICS.