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
errno
to some value , what does it do ? just error checking ?How can I set
errno
in the above methodsfunc1
andfunc2
toEEXIST
andENOENT
Thanks
IMO, the standard
errno
designed for system level. My experience is do not pollute them. If you want to simulate the C standarderrno
mechanism, you can do some definition like:and also you can still implement
your_perror(err_code)
. More information, please refer to glibc's implementation.For all practical purposes, you can treat
errno
like a global variable (although it's usually not). So includeerrno.h
and just use it:You should ask yourself if
errno
is the best error-reporting mechanism for your purposes. Can the functions be engineered to return the error code themselves ?