U
Urs Beeli
I have a question regarding errno. If I understand it correctly,
including <errno.h> allows me to check "errno" for error values
that some standard library functions may set.
This brings up some questions:
- As I understand it, most functions only set errno in an error
case. I take this to mean, that on success, errno is not
necessarily set to EOK and I would either need to set errno
to EOK before calling the function in question to determine
its outcome or I would need to check the return value first,
and then in an error case inspect errno to get more details.
Is this understanding correct?
- Am I allowed to modify errno in my own functions as well? I
would say yes, but am not sure.
- Assuming I may modify errno in my own functions, I guess it
would also be ok for me to set it to EOK on success to allow
someone to determine the success/failure of my function by
purely inspecting the return value (I would probably tend
to just return errno at the end of the function, so both
approaches would work). Is this true?
- I am assuming that errno is a global integer value. Is this
correct?
<OT>
And the last question leads me to the announced off-topic follow-up
question:
- if errno is implemented with a global variable, how can any
multi-threaded application (and I know that this is beyond
the C standard) such as a POSIX implementation support standard
functions that make use of errno?
- is there an obvious trick on how to implement errno differently
that I am missing?
- or can those functions still be used but errno may not be
evaluated safely?
- or does POSIX redefine the C standard library to not make
use of errno
- any other solution/situation I did not think of?
</OT>
Looking forward to enlightment
/urs
including <errno.h> allows me to check "errno" for error values
that some standard library functions may set.
This brings up some questions:
- As I understand it, most functions only set errno in an error
case. I take this to mean, that on success, errno is not
necessarily set to EOK and I would either need to set errno
to EOK before calling the function in question to determine
its outcome or I would need to check the return value first,
and then in an error case inspect errno to get more details.
Is this understanding correct?
- Am I allowed to modify errno in my own functions as well? I
would say yes, but am not sure.
- Assuming I may modify errno in my own functions, I guess it
would also be ok for me to set it to EOK on success to allow
someone to determine the success/failure of my function by
purely inspecting the return value (I would probably tend
to just return errno at the end of the function, so both
approaches would work). Is this true?
- I am assuming that errno is a global integer value. Is this
correct?
<OT>
And the last question leads me to the announced off-topic follow-up
question:
- if errno is implemented with a global variable, how can any
multi-threaded application (and I know that this is beyond
the C standard) such as a POSIX implementation support standard
functions that make use of errno?
- is there an obvious trick on how to implement errno differently
that I am missing?
- or can those functions still be used but errno may not be
evaluated safely?
- or does POSIX redefine the C standard library to not make
use of errno
- any other solution/situation I did not think of?
</OT>
Looking forward to enlightment
/urs