How to use errno in embedded linux

Hello, we're getting the hang of embedded linux, and we have a call to the POSIX command (in unistd.h) "write" that sometimes returns -1 indicating failure, and we have no idea why (happen to be writing to a USB port).

So I did a little digging and found that a lot of these POSIX commands set something called errno when they fail, which appears to be a centralized error code, which seemed like something we could use.  We included "errno.h" and set the errno to zero before the call that sometimes fails, and then after it fails it is set to 11.

So trying to figure out what that means, consulted this link:

http://publib.boulder.ibm.com/infocenter/iseries/v7r1m0/index.jsp?topic=%2Fapis%2Funix14.htm

which actually doesn't have an 11, so I assumed that it means 3011, which sorta fits because it is ESTDOUT "The stdout stream cannot be opened.", not very useful but the right direction.  However, consulting this page:

http://pubs.opengroup.org/onlinepubs/7908799/xsh/write.html

does NOT list ESTDOUT as one of the possible errnos.  

So:

* are we misinterpreting our value of ESTDOUT?
* does that error make sense for the write command
* why would the write command intermittently fail to a USB port?

Thanks very much for any insight!
RonMexicoAsked:
Who is Participating?
 
jkrCommented:
That could be a lot of things, and given the nature of USB communications, I'd just guess that something else is going on on the bus at that very moment. IMO the best thing is to do what the name of the error code suggest - trying the 'write()' request again until it can be completed successfuly, e.g. (pseudocode):

int ret;

do {

  ret = write(...);

} while (ret == -1 && errno == EAGAIN);

// check other error conditions:
if (ret == -1) {

  // evaluate errno for different values
}

Open in new window

0
 
jkrCommented:
Acutally, errno 11 is EAGAIN (IIRC) or "Resource temporarily unavailable" (http://linux.die.net/man/3/errno)
0
 
RonMexicoAuthor Commented:
Oh... that would be consistent with the intermittent nature.  Your web link didn't have numbers, do you just have that memorized?  That IBM page has EAGAIN as 3406... meaning I will never again use that page.

So we are relatively new to linux, and you are clearly expert (or more accurate guru by the list to the right).  What kinds of things can cause "resource temporarily unavailable" for a USB port?
0
 
RonMexicoAuthor Commented:
Thanks very much jkr!
0
 
jkrCommented:
You're welcome ;o)

BTW, adding a delay in the above loop would help to make that less CPU-intensive.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.