warn(), warnx()

Formatted error message

Synopsis:

#include <err.h>

void warn( const char* fmt, ...);

void warnx( const char* fmt, ...);

Arguments:

fmt
NULL, or a printf()-style string used to format the message.
Additional arguments
As required by the format string.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The err() and warn() family of functions display a formatted error message on stderr. For a comparison of the members of this family, see err().

The warn() function produces a message that consists of:

The warnx() function produces a similar message, except that it doesn't include the string associated with errno. The message consists of:

Examples:

Warn of an error:

if ((fd = open(raw_device, O_RDONLY, 0)) == -1)
    warnx("%s: %s: trying the block device",
          raw_device, strerror(errno));
if ((fd = open(block_device, O_RDONLY, 0)) == -1)
    warn("%s", block_device);

Classification:

Unix

Safety:  
Cancellation point Yes
Interrupt handler No
Signal handler Yes
Thread Yes