[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 Base Operating System and Extensions Technical Reference, Volume 1

perror Subroutine

Purpose

Writes a message explaining a subroutine error.

Library

Standard C Library (libc.a)

Syntax

#include <errno.h>
void perror (String)
const char *String;
extern int errno;
extern char *sys_errlist[ ];
extern int sys_nerr;

Description

The perror subroutine writes a message on the standard error output that describes the last error encountered by a system call or library subroutine. The error message includes the String parameter string followed by a : (colon), a space character, the message, and a new-line character. The String parameter string should include the name of the program that caused the error. The error number is taken from the errno global variable, which is set when an error occurs but is not cleared when a successful call to the perror subroutine is made.

To simplify various message formats, an array of message strings is provided in the sys_errlist structure or use the errno global variable as an index into the sys_errlist structure to get the message string without the new-line character. The largest message number provided in the table is sys_nerr. Be sure to check the sys_nerr structure because new error codes can be added to the system before they are added to the table.

The perror subroutine retrieves an error message based on the language of the current locale.

After successfully completing, and before a call to the exit or abort subroutine or the completion of the fflush or fclose subroutine on the standard error stream, the perror subroutine marks for update the st_ctime and st_mtime fields of the file associated with the standard error stream.

Parameter

String Specifies a parameter string that contains the name of the program that caused the error. The ensuing printed message contains this string, a : (colon), and an explanation of the error.

Implementation Specifics

This subroutine is part of Base Operating System (BOS) Runtime.

Related Information

The abort subroutine, exit subroutine, fflush or fclose subroutine, printf, fprintf, sprintf, wsprintf, vprintf, vfprintf, vsprintf, or vwsprintf subroutine, strerror subroutine.

Subroutines Overview in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.


[ Previous | Next | Contents | Glossary | Home | Search ]