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:

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:

does NOT list ESTDOUT as one of the possible errnos.  


* 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!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Acutally, errno 11 is EAGAIN (IIRC) or "Resource temporarily unavailable" (
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?
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RonMexicoAuthor Commented:
Thanks very much jkr!
You're welcome ;o)

BTW, adding a delay in the above loop would help to make that less CPU-intensive.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.