Robert Krten <nospam89@parse.com> wrote:
David Gibbs <> dagibbs@qnx.com> > wrote:
Michael Tasche <> michael.tasche@esd-electronics.com> > wrote:
Hi all,
on my 6.2 Beta (bld447) the devctl does not set errno. Instead the ernno
code is returned by devctl.
Well, this seems to match the docu about devctl, but if you look at the
example, you see following:
if (devctl (fd, DCMD_CHR_SERCTL, &data, sizeof(data), NULL))
{
fprintf(stderr, “Error setting RTS.\n”);
perror (NULL);
exit(EXIT_FAILURE);
}
The “perror” will ever say “No error”, because ernno is not set.
Which behavior is intended by qnx?
The example is bad.
Hey Dave, why is the example bad?
A couple reasons.
It assumes that devctl() will set errno, and that the perror() can be
used to display the reason that devctl() failed. (FALSE)
It assumes that a successful fprintf() will NOT set errno, thus losing
the failure reason from devctl().
It is at best confusing – is perror() trying to display the reason
devctl() failed (we ARE in the devctl() function docs) or the reason
fprintf() failed, should it have failed?
If fprintf() succeeds, then it should not touch
errno, right? I use the fprintf()/perror() all the time…
Are you saying it’s bad in the case of devctl()/fprintf()/perror(),
or in all general cases of fprintf()/perror()?
My understanding is that a function IS allowed to update errno whether
or not it has failed.
The usual specification for functions is something like, “retuns blah
on success, and blah2 if failure, in which case errno will be set, list
of errno values”. For those functions, errno only has meaning if the
function failed – it might or might not get changed along the way.
Some functions (I think some of the math functions) actually always
set errno, set it to EOK if the function succeeded, or to some failure
value if they failed.
Now, fprintf() might happen to not set errno if it succeeds, but this
is not guaranteed behaviour.
-David
QNX Training Services
http://www.qnx.com/support/training/
Please followup in this newsgroup if you have further questions.