我应该设置错误号? [英] Should I set errno?
问题描述
我正在写出口类似的接口发送模块
和的recv
。
I'm writing a module which exports an interface similar to send
and recv
.
由于这些功能都应该分别返回发送和接收的字节数,我不能做正确的错误管理,我会(即使用和enumeratives返回助记符值)做正常。
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?
编辑:尝试它,我注意到,设置错误号
由分配工作。还是:这是安全和便携的任何系统
experimenting it I noticed that setting errno
by assignment is working. Still: is this safe and portable for any system?
推荐答案
这是有点老了,但错误号 - 手动节3 说,你可以直接分配给它,即使它是一个宏观的,这将是线程本地
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
这篇关于我应该设置错误号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!