Should I set errno?

Dacav picture Dacav · Mar 25, 2012 · Viewed 16.7k times · Source

I'm writing a module which exports an interface similar to send and recv.

Since those functions are supposed to return respectively the number of sent and received bytes, I cannot do proper error management as I would do normally (i.e. using enumeratives and returning mnemonic values).

In a situation like this should I set errno as the standard library does? If so, since errno is thread specific, is there a particular way of writing on it, or can I simply assign a value to it?

Edit: experimenting it I noticed that setting errno by assignment is working. Still: is this safe and portable for any system?

Answer

gbulmer picture gbulmer · Mar 25, 2012

This is a bit old, but errno - manual section 3 says that you can directly assign to it, even though it is a macro, and it will be thread local