O'Reilly logo

Advanced UNIX Programming by Warren W. Gay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reporting on errno Values

When an error occurs, it is simple for the program to test for a specific case and act upon it. The problem becomes more complex when all you want to do is report the error to the user. Users do not like to memorize error codes, so a method must exist to translate an errno code into a readable message.

Meaningful error messages can be reported by a UNIX program to the user, in the following ways:

  • Use the perror(3) function to generate a message from the errno value and report it to stderr.

  • Use the provided sys_errlist[] array of messages (on FreeBSD this is described by the man page strerror(3)).

  • Use the strerror(3) function to return a message for the error code provided in the function argument.

Using the perror(3)

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required