Where is the errnos defined? Example linux c/c++ program for i2c.

Posted by Johan on Stack Overflow See other posts from Stack Overflow or by Johan
Published on 2011-03-15T15:21:46Z Indexed on 2011/03/15 16:10 UTC
Read the original article Hit count: 216

Filed under:
|
|
|
|

Hi

When something goes wrong in a classic linux c/c++ software we have the magic variable errno that gives us a clue on what just went wrong.

But where is those errors defined?

Let's take a example (it's actually a piece from a Qt app, therefore the qDebug()).

if (ioctl(file, I2C_SLAVE, address) < 0) {
    int err = errno;
    qDebug() << __FILE__ << __FUNCTION__ << __LINE__ 
        << "Can't set address:" << address
        << "Errno:" << err << strerror(err);
     ....

The next step is to look at what that errno was so we can decide if we just quit or try to do something about the problem.

So we maybe add a if or switch at this point.

if (err == 9)
{
    // do something...
}
else 
{
    //do someting else
}

And my question is where to find the errors that "9" represents? I don't like that kind of magic numbers in my code.

/Thanks

© Stack Overflow or respective owner

Related posts about c++

Related posts about c