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?
The problem is you redeclared
errno, thereby shadowing the global symbol (which need not even be a plain variable). The effect is that whatopensets and what you’re printing are different things. Instead you should include the standarderrno.h.