Question

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.

Was it helpful?

Solution

You can use strerror():

fprint( stderr, "error: %s\n", strerror( errno ) );

OTHER TIPS

From the vxWorks :

A string constant associated with errno can be displayed using printErrno( ) if the errno value has a corresponding string entered in the error-status symbol table, statSymTbl. See the VxWorks API reference for errnoLib for details on error-status values and building statSymTbl.

So to print String associated with an errno: printErrno(errno)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top