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

Xref: news2.mv.net comp.os.msdos.djgpp:1981
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 14:53:07 -0500
Organization: Teleglobe Canada Inc.
Lines: 55
Message-ID: <314F10A3.1C7E@teleglobe.ca>
References: <JTSILLA DOT 96Mar18092345 AT everest DOT ccs DOT neu DOT edu>
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

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);
}
------------------

- Raw text -


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