www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/03/19/21:18:06

Xref: news2.mv.net comp.os.msdos.djgpp:1983
From: Denis Bernard <dbernard AT teleglobe DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Is this a bug with open() (V2).
Date: Tue, 19 Mar 1996 15:17:41 -0500
Organization: Teleglobe Canada Inc.
Lines: 61
Message-ID: <314F1665.59DF@teleglobe.ca>
References: <JTSILLA DOT 96Mar18092345 AT everest DOT ccs DOT neu DOT edu> <314F10A3 DOT 1C7E AT teleglobe DOT ca>
NNTP-Posting-Host: bnet-gw.teleglobe.ca
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019