By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,433 Members | 1,797 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,433 IT Pros & Developers. It's quick & easy.

how to handle open() errors?

P: n/a
Opening /dev/tap0, I have an error in fact open() returns -1.

int fd = open("/dev/tap0",O_RDWR);
if (fd == -1)
{
cerr<<"error opening interface"<<endl;
}

How can I handle the error? Essentially, how can I print the error to
know the reason of it?

Thanks.

Nov 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
fabrizio wrote:
Opening /dev/tap0, I have an error in fact open() returns -1.

int fd = open("/dev/tap0",O_RDWR);
if (fd == -1)
{
cerr<<"error opening interface"<<endl;
}

How can I handle the error? Essentially, how can I print the error to
know the reason of it?

Thanks.


perror will print an error message to the standard error stream

int fd = open("/dev/tap0",O_RDWR);
if (fd == -1)
{
perror("error opening interface");
}

There are of coure no guarantees that the error message will be helpful.

john
Nov 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.