elanktronik elanktronik - 5 months ago 17
Linux Question

Linux open issue

I am having a problem with "open". even if there is no device named ttyACM3, it does not return an error. it always prints "no error".

What could be the problem ?

fd = open("/dev/ttyACM3", O_RDWR);
printf("no error");

Answer Source

This line:


Would evaluate to true for fd == -1, which is how open returns an error. open returns -1 on error, not 0.

In the future read the documentation more carefully :)

Also if (fd) evaluates to true for negative numbers, in case you were wondering.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download