On 9/13/07, Bachman Kharazmi <[EMAIL PROTECTED]> wrote:
> #include <errno.h>
> ...
> int main(int argc){
> int fd,err;
> extern int errno;
> char* myString = "helloworld\n";
> errno=0;
> fd = open("rtser0", O_RDWR);
> printf("errno is : %d\n",errno);
> if (fd < 0) {
> printf(MAIN_PREFIX "1 : can't open %s (write), %s\n",
> WRITE_FILE,
> strerror(-fd));
> return fd;
> }
>
> sandbox:/home/bkw/code/driver_v4# ./simpledriver_v4
> errno is : 2
> main : 1 : can't open rtser0 (write), Operation not permitted
>
> Correct way of using errno?
No, as indicated in errno manual page, the value of errno is defined
only if a system call indicates a failure. So, the correct way of
using errno is:
fd = open("rtser0", O_RDWR)
if (fd == -1) {
fprintf(stderr, "open(rtser0): %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
or:
if (fd == -1) {
perror("open(rtser0)");
exit(EXIT_FAILURE);
}
Anyway, 2 is ENOENT strerror(2) is "No such file or directory"
It probably means that you are not compiling your program with the
flags returned by xeno-config.
--
Gilles Chanteperdrix
_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help