RAD Studio
ContentsIndex
PreviousUpNext
perror,_wperror

Header File 

errno.h, stdio.h  

Category 

Diagnostic Routines, Input/output Routines 

Prototype 

void perror(const char *s); 

void _wperror(const wchar_t *s); 

Description 

Prints a system error message. 

perror prints to the stderr stream (normally the console) the system error message for the last library routine that set the global variable errno. 

It prints the argument s followed by a colon (:) and the message corresponding to the current value of the global variable errno and finally a new line. The convention is to pass the file name of the program as the argument string. 

The array of error message strings is accessed through the global variable _sys_errlist. The global variable errno can be used as an index into the array to find the string corresponding to the error number. None of the strings include a newline character. 

The global variable _sys_nerr contains the number of entries in the array. 

The following messages are generated by perror:

Note: For Win32 GUI applications, stderr must be redirected.
Arg list too big 

Attempted to remove current directory 

Bad address 

Bad file number  

Block device required 

Broken pipe  

Cross-device link 

Error 0 

Exec format error 

Executable file in use 

File already exists  

File too large  

Illegal seek 

Inappropriate I/O control operation 

Input/output error 

Interrupted function call  

Invalid access code  

Invalid argument Resource busy 

Invalid dataResource temporarily unavailable 

Invalid environment  

Invalid format  

Invalid function number 

Invalid memory block address 

Is a directory 

Math argument 

Memory arena trashed 

Name too long 

No child processes 

No more files 

No space left on device 

No such device 

No such device or address 

No such file or directory 

No such process 

Not a directory 

Not enough memory 

Not same device 

Operation not permitted 

Path not found 

Permission denied 

Possible deadlock 

Read-only file system 

Resource busy 

Resource temporarily unavailable 

Result too large 

Too many links 

Too many open files 

Example  

#include <stdio.h>
int main(void)
{
    FILE *fp;
    fp = fopen("perror.dat", "r");
    if (!fp)
       perror("Unable to open file for reading");
    return 0;
}

Portability

 
POSIX 
Win32 
ANSI C 
ANSI C++ 
perror 
_wperror 
 
 
 
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!