# perror

## NAME



           perror - print a system error message
    


## LIBRARY



           Standard C library (_libc_ , _-lc_)
    


## SYNOPSIS



           **#include <stdio.h>**
    
           **void perror(const char ***_s_**);**
    
           **#include <errno.h>**
    
           **int** _errno_**;** /* Not really declared this way; see errno(3) */
    
           **[[deprecated]] const char *const** _sys_errlist_**[];**
           **[[deprecated]] int** _sys_nerr_**;**
    
       Feature Test Macro Requirements for glibc (see
       feature_test_macros(7)):
    
           _sys_errlist_ , _sys_nerr_ :
               From glibc 2.19 to glibc 2.31:
                   _DEFAULT_SOURCE
               glibc 2.19 and earlier:
                   _BSD_SOURCE
    


## DESCRIPTION



           The **perror**() function produces a message on standard error
           describing the last error encountered during a call to a system or
           library function.
    
           First (if _s_ is not NULL and _*s_ is not a null byte ('\0')), the
           argument string _s_ is printed, followed by a colon and a blank.
           Then an error message corresponding to the current value of _errno_
           and a new-line.
    
           To be of most use, the argument string should include the name of
           the function that incurred the error.
    
           The global error list _sys_errlist_[], which can be indexed by
           _errno_ , can be used to obtain the error message without the
           newline.  The largest message number provided in the table is
           _sys_nerr_ -1.  Be careful when directly accessing this list, because
           new error values may not have been added to _sys_errlist_[].  The
           use of _sys_errlist_[] is nowadays deprecated; use strerror(3)
           instead.
    
           When a system call fails, it usually returns -1 and sets the
           variable _errno_ to a value describing what went wrong.  (These
           values can be found in _< errno.h>_.)  Many library functions do
           likewise.  The function **perror**() serves to translate this error
           code into human-readable form.  Note that _errno_ is undefined after
           a successful system call or library function call: this call may
           well change this variable, even though it succeeds, for example
           because it internally used some other library function that
           failed.  Thus, if a failing call is not immediately followed by a
           call to **perror**(), the value of _errno_ should be saved.
    


## ATTRIBUTES



           For an explanation of the terms used in this section, see
           attributes(7).
           ┌──────────────────────────┬───────────────┬─────────────────────┐
           │ **Interface** │ **Attribute** │ **Value** │
           ├──────────────────────────┼───────────────┼─────────────────────┤
           │ **perror**()                 │ Thread safety │ MT-Safe race:stderr │
           └──────────────────────────┴───────────────┴─────────────────────┘
    


## STANDARDS



           _errno_
           **perror**()
                  C11, POSIX.1-2008.
    
           _sys_nerr_
           _sys_errlist_
                  BSD.
    


* * *