In vxworks, when an api call returns ERROR, it often sets errno.
We can access this using errnoGet(), and, from the shell, we can translate that into a meaningful string using printErrno()
Is there a function I can call from my C code that will do this translation and return a char* suitable?
The example below illustrates, however note that this is a MVCE, and use of printf is for example only - in the real world this would be used as part of a custom error handler that does not do screen output.
eg
STATUS badFunc()
{
errnoSet(S_someErrnoVal);
return ERROR;
}
void anotherFunc()
{
if(badFunc()==ERROR)
{
//currently, I end up just calling printErrno() here
//but if there was some function errnoToText() i could do something like:
printf("badFunc failed, errno %d, error string%s",errnoGet(), errnoToText(errnoGet()));
}
}
I am sure I used to have such a function available, but I cant find any reference in the programmers guide.
You can use strerror():
fprint( stderr, "error: %s\n", strerror( errno ) );