I have two calls to two different methods :
void func1()
{
// do something
if (fail)
{
// then set errno to EEXIST
}
}
And the second method :
void func2()
{
// do something
if (fail)
{
// then set errno to ENOENT
}
}
-
When I set the
errnoto some value , what does it do ? just error checking ? -
How can I set
errnoin the above methodsfunc1andfunc2toEEXISTandENOENT
Thanks
For all practical purposes, you can treat
errnolike a global variable (although it’s usually not). So includeerrno.hand just use it:You should ask yourself if
errnois the best error-reporting mechanism for your purposes. Can the functions be engineered to return the error code themselves ?