Determining Success or Failure

When a C function is called, the programmer is interested in two things upon its return:

  • Did the function call succeed?

  • If not, why did the call fail?

General Rules for Error Indication

The UNIX convention used by most system calls and library functions is that the return value indicates a general success or failure. Return values fall into two major categories:

  • The return value is an integer value (int or long). Normally failure is indicated by a value of negative one (-1).

  • The return value is a pointer type, such as pointers (char *), (void *) or a pointer to a structure. Failure is indicated by a null return pointer and success by a non-null pointer.

Exceptions to the General Rule

There are exceptions to the general ...

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.