as3rdaccount
as3rdaccount

Reputation: 3931

How to extract error from a system call?

For example in man page it says:

The mmap() function shall fail if:

EACCES
The fildes argument is not open for read, regardless of the protection specified,        
fildes is not open for write and PROT_WRITE was specified for a MAP_SHARED type 
mapping. 

There are bunch of other cases. I am assuming there is a way to check which error has occurred however a hour of search yielded nothing. How do you check if that particular error has occured?

Upvotes: 0

Views: 188

Answers (2)

Jeff White
Jeff White

Reputation: 43

You could also do this if you are using C++

std::cerr << strerror(errno) << std::endl;

More detailed information can be found here:

C++ alternative to perror()

Upvotes: 0

Carl Norum
Carl Norum

Reputation: 224844

That error value will be saved in the global variable errno. You can get a human readable string from perror(3).

Upvotes: 1

Related Questions