In my code open() fails with a return code of -1 but somehow errno is not getting set.
int fd;
int errno=0;
fd = open("/dev/tty0", O_RDWR | O_SYNC);
printf("errno is %d and fd is %d",errno,fd);
output is
errno is 0 and fd is -1
Why is errno not being set? How can i determine why open() fails?
int errno=0;
The problem is you redeclared errno, thereby shadowing the global symbol (which need not even be a plain variable). The effect is that what open sets and what you're printing are different things. Instead you should include the standard errno.h.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With