Why is 'EINTR' undeclared?

时间:2017-04-10 02:54:51

标签: c unix io

I included <error.h>.

#include <error.h>
#include <unistd.h>

ssize_t rio_readn(int fd, void *buf, size_t n)
{
    size_t nleft = n;
    char *rbuf = buf;
    while(nleft > 0)
    {
        int nread = read(fd, rbuf, nleft);
        if(nread < 0)
        {
            if(error == EINTR)
                nread = 0;
            else
                return -1;
        }
        else if(nread == 0)
            break;
        nleft -= nread;
        rbuf += nread;
    }
    return n - nleft;
}

1 个答案:

答案 0 :(得分:8)

You're missing the declaration for EINTR because <error.h> has no relation to <errno.h>, which is where EINTR is declared. And the error variable is errno and not error, too.