Nick
April 26, 2001, 1:22pm
1
I have 2 QNX 6 (Patch B) computers (large and small), connected via Qnet.
#uname -a
#QNX large 6.00 2001/02/22-08:59:07est x86pc x86
Network looks fine. I’m trying to write file to Qnet’ed machine named
“small”.
Command
#cat any_file > /net/small/home/rk/filename
works fine. OK. So, I used small example like one from “Getting Started with
QNX Neutrino 2” Mr’s. Rob Krten (p. 101):
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
int main(void)
{
int fd;
int ret;
fd = open("/net/small/home/rk/filename",
// O_WRONLY
O_CREAT, S_IRUSR | S_IWUSR
);
perror(“after open”);
ret = write(fd, “This is message passing”, 24);
perror(“after write”);
close(fd);
return (EXIT_SUCCESS);
}
With O_WRONLY flag in open() call result is:
after open: No such file or directory
#after write: Bad file descriptor
With O_CREAT flag and S_IRUSR | S_IWUSR mode:
after open: No error
#after write: Bad file descriptor
file /home/rk/filename on machine small was created, but with zero length.
Any ideas ?
Nick
Previously, Nick wrote in qdn.public.qnxrtp.devtools:
I have 2 QNX 6 (Patch B) computers (large and small), connected via Qnet.
#uname -a
#QNX large 6.00 2001/02/22-08:59:07est x86pc x86
Network looks fine. I’m trying to write file to Qnet’ed machine named
“small”.
Command
#cat any_file > /net/small/home/rk/filename
works fine. OK. So, I used small example like one from “Getting Started with
QNX Neutrino 2” Mr’s. Rob Krten (p. 101):
#include <stdio.h
#include <fcntl.h
#include <unistd.h
#include <sys/types.h
#include <sys/stat.h
#include <stdlib.h
int main(void)
{
int fd;
int ret;
fd = open("/net/small/home/rk/filename",
// O_WRONLY
O_CREAT, S_IRUSR | S_IWUSR
);
perror(“after open”);
ret = write(fd, “This is message passing”, 24);
perror(“after write”);
close(fd);
return (EXIT_SUCCESS);
}
With O_WRONLY flag in open() call result is:
after open: No such file or directory
#after write: Bad file descriptor
With O_CREAT flag and S_IRUSR | S_IWUSR mode:
after open: No error
#after write: Bad file descriptor
file /home/rk/filename on machine small was created, but with zero length.
Any ideas ?
Nick
Try sending the open mode as:
O_RDWR | O_CREAT
or
O_WRONLY | O_CREAT
The open mode needs O_CREAT if the file does not exist, and one form
of write permission. Your problem is that you are giving one or the
other of O_CREAT and O_WRONLY. You need both.
Cheers,
Andrew
On Thu, 26 Apr 2001 10:32:08 +0000, Andrew Thomas <Andrew@cogent.ca >
wrote:
Previously, Nick wrote in qdn.public.qnxrtp.devtools:
I have 2 QNX 6 (Patch B) computers (large and small), connected via Qnet.
#uname -a
#QNX large 6.00 2001/02/22-08:59:07est x86pc x86
Network looks fine. I’m trying to write file to Qnet’ed machine named
“small”.
Command
#cat any_file > /net/small/home/rk/filename
works fine. OK. So, I used small example like one from “Getting Started with
QNX Neutrino 2” Mr’s. Rob Krten (p. 101):
#include <stdio.h
#include <fcntl.h
#include <unistd.h
#include <sys/types.h
#include <sys/stat.h
#include <stdlib.h
int main(void)
{
int fd;
int ret;
fd = open("/net/small/home/rk/filename",
// O_WRONLY
O_CREAT, S_IRUSR | S_IWUSR
);
perror(“after open”);
ret = write(fd, “This is message passing”, 24);
perror(“after write”);
Side note: beware that errno is set only if an error occured, hence
if the write or open succeed the output of perror can
be misleading as it would show error of a previous function that
failed. In theory you should check ret and if( ret == -1 ) then
use perror.
Nick
April 27, 2001, 8:39am
4
Thanks, Andrew, it’s working!
Nick
“Andrew Thomas” <Andrew@cogent.ca > wrote in message
news:Voyager.010426103208.569378A@andrewhome.cogent.ca …
Previously, Nick wrote in qdn.public.qnxrtp.devtools:
I have 2 QNX 6 (Patch B) computers (large and small), connected via
Qnet.
#uname -a
#QNX large 6.00 2001/02/22-08:59:07est x86pc x86
Network looks fine. I’m trying to write file to Qnet’ed machine named
“small”.
Command
#cat any_file > /net/small/home/rk/filename
works fine. OK. So, I used small example like one from “Getting Started
with
QNX Neutrino 2” Mr’s. Rob Krten (p. 101):
#include <stdio.h
#include <fcntl.h
#include <unistd.h
#include <sys/types.h
#include <sys/stat.h
#include <stdlib.h
int main(void)
{
int fd;
int ret;
fd = open("/net/small/home/rk/filename",
// O_WRONLY
O_CREAT, S_IRUSR | S_IWUSR
);
perror(“after open”);
ret = write(fd, “This is message passing”, 24);
perror(“after write”);
close(fd);
return (EXIT_SUCCESS);
}
With O_WRONLY flag in open() call result is:
after open: No such file or directory
#after write: Bad file descriptor
With O_CREAT flag and S_IRUSR | S_IWUSR mode:
after open: No error
#after write: Bad file descriptor
file /home/rk/filename on machine small was created, but with zero
length.
Any ideas ?
Nick
Try sending the open mode as:
O_RDWR | O_CREAT
or
O_WRONLY | O_CREAT
The open mode needs O_CREAT if the file does not exist, and one form
of write permission. Your problem is that you are giving one or the
other of O_CREAT and O_WRONLY. You need both.
Cheers,
Andrew