Mail Archives: djgpp/1996/03/19/21:18:06
Denis Bernard wrote:
>
> James Tsillas wrote:
> >
> > Hi world,
> >
> > I'm trying to create a file with the open system call and it appears to
> > succeed, returning a file descriptor greater than or equal to zero.
> > Errno is set to the "file doesn't exist" which appears to be normal. I
> > am using the CREAT flag and file gets created, etc. Now, it appears that
> > my file descriptor (returned from open) is 0. And (even more weird) when
> > I try to write to this file, the output goes to the terminal and the
> > file isn't written to. I recall that 0 was the standard fd for stdin in
> > POSIX.
> >
> > Shouldn't open() return an unused fd? I wish I could give the precise
> > source but my source is on a different computer. One point to take note
> > of: I create the file as write only.
> >
> > Is this a bug? If not, can I see a working example? If so, is there a
> > workaround? Nothing in the FAQ.
> >
> > ciao,
> > -Jim.
> > --
> >
> > ____***___
> > \..*...*./
> > \.*..../
> > \*...* * Jim Tsillas - Senior Software Engineer *
> > \**/ * Cascade Communications Corp. *
> > \/ * 5 Carlisle Road, Westford MA 01886 *
> > CASCADE
> >
>
> It works fine for me... Try it like this.
>
> Denis.
>
> ------------
> #include <fcntl.h>
> #include <sys/stat.h>
> #include <stdlib.h>
>
> main()
> {
> int descr;
> if ((descr = open("x.x", O_CREAT|O_WRONLY|O_BINARY)) < 0) {
> perror("Bug");
> exit(1);
> }
>
> close (descr);
> exit(0);
> }
> ------------------
forgot...
use open("x.x", O_CREAT|O_WRONLY|O_BINARY, S_IWUSR) for non "read-only"
files or else you will have to "attrib -r" your files before deleting
your files...
- Raw text -