Re: your mail

Richard B. Johnson
2003-12-03T15:44:57Z

On Wed, 3 Dec 2003, Bloch, Jack wrote:

> I try to open a non-existan device driver node file. The Kernel returns a
> value of -1 (expected). However, when I read the value of errno it contains
> a value of 29. A call to the perror functrion does print out the correct
> error message (a value of 2). Why does this happen?
>
> Jack Bloch
> Siemens ICN
> phone (561) 923-6550
> e-mail jack.bloch@icn.siemens.com

Because it doesn't happen! You are likely polluting the errno
variable either with another system call before you test it
or by not including the correct header file (errno may be a
MACRO).

Try this program:

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>

int main(int args, char *argv[])
{
int fd, save_errno;
if(args < 2) {
fprintf(stderr, "Usage:\n%s <filename>\n", argv[0]);
exit(EXIT_FAILURE);
}
if((fd = open(argv[1], O_RDONLY)) < 0) {
save_errno = errno;
perror("open");
fprintf(stderr, "Was %d (%s)\n", save_errno, strerror(save_errno));
exit(EXIT_FAILURE);
}
(void)close(fd);
return 0;
}

Script started on Wed Dec 3 10:41:24 2003
# ./xxx /dev/XXX
open: No such file or directory
Was 2 (No such file or directory)
# ./xxx /dev/VXI
open: Operation not supported by device
Was 19 (Operation not supported by device)
# exit
exit
Script done on Wed Dec 3 10:42:12 2003

Cheers,
Dick Johnson
Penguin : Linux version 2.4.22 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.