bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: full_read depends on incoming errno


From: Paolo Bonzini
Subject: Re: full_read depends on incoming errno
Date: Thu, 21 Feb 2013 18:16:17 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]