2

I'm writing a program for Systems Programming in Unix, and one of the requirements is to process all possible error returns from system calls.

So, rather than having a function tailored to each system call, I'd like to have one function take care of that responsibility. So, are all error number returns unique? If not, what areas of overlap exist?

asked Mar 20, 2011 at 22:23

3 Answers 3

3

There are two aspects: the ways system calls signal that an error occurred, and the way what error occurred is reported.

Most system calls signal that an error occurred by returning -1, but this is not completely universal (for example, some system calls are always successful, e.g. getpid).

If you know an error occurred, the error code is always in errno1. There are standard values defined in errno.h, and every unix variants adds a few of its own. Error codes are known by constants whose name begins with E; the numeric values vary from OS to OS. These error codes are standard (e.g. EACCESS always means "permission denied", EIO always means "input/output error", ...), but what precisely each error message means depends on the system call.

The standard functions strerror and perror provide error messages that you can display to a user.

1 Note that if no error occurred during the last system call or C library function call, errno may contain garbage.

answered Mar 20, 2011 at 23:02
2

The only overlaps I'm aware of are synonyms in areas that historically have differed between AT&T and BSD-derived Unixes. For example, AT&T Unix's EAGAIN means the same thing as BSD's EWOULDBLOCK, so they have the same value on systems that define both.

answered Mar 20, 2011 at 23:03
0

No, there should be no overlaps in errno.h on a given system. Check your errno.h (most likely somewhere under /usr/include) for defines starting with E, as in ENOENT and such, and make a switch() statement handling each case. Then you can call your own function for all system call errors.

(Sounds a lot like you're implementing perror(3).

answered Mar 21, 2011 at 10:29

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.