perror()                 Print Error Message
 
 #include   <stdlib.h>                   Required for declarations only
 
 void       perror(string);
 char       *string;                     User-supplied message
 
 int        errno;                       Error number
 int        sys_nerr;                    Number of system messages
 char       sys_errlist[sys_nerr];       Array of error messages
 
    perror() prints an error message to 'stderr'.  In order, perror()
    prints:
 
            the user-supplied string argument
            a colon
            system error message for last library call producing an error
            a new-line character
 
    System error messages are accessed through an array of messages,
    ordered by 'errno', called 'sys_errlist'.  The error number generated
    by the most recent system call is stored in the external variable,
    'errno' (which should be declared at the external level); 'errno'
    thus reflects the most recent error generated by a system library
    call in the current program.  perror uses errno as an index to
    sys_errlist to print the appropriate error message.  'sys_nerr'
    contains the maximum number of elements in 'sys_errlist'.
 
    Returns:    There is no return value.
 
      Notes:    Call perror() immediately after the system call returns
                with an error. Otherwise, the error number in 'errno' may
                be overwritten by an error generated by a subsequent
                system call.
 
  -------------------------------- Example ---------------------------------
 
         #include <fcntl.h>                /* constants defined */
         #include <sys\types.h>
         #include <sys\stat.h>             /* constants defined */
         #include <io.h>                   /* for open */
         #include <stdlib.h>
 
 
         int fhndl;
 
         main()
         {
             if ((fhndl = open("inp.dat",O_RDONLY)) == -1)
                 perror("unable to open file");
         }

Seealso:



This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster