www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/21/06:34:40

Date: Tue, 21 Apr 1998 13:33:04 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Andreas Kochenburger <kochenbu AT khe DOT scn DOT de>
cc: djgpp AT delorie DOT com
Subject: Re: Bug in djgpp 2.8.0b with open()?
In-Reply-To: <353b0193.4405066@news>
Message-ID: <Pine.SUN.3.91.980421132718.1009H-100000@is>
MIME-Version: 1.0

On Mon, 20 Apr 1998, Andreas Kochenburger wrote:

> Is this a bug in djgpp (downloaded freshly from www.delorie.com).?
> 
> The problem occurs when you run open.exe twice,
> i.e. open.tst already exists.

This isn't a bug in djgpp, it's a bug in your program.

>    mode = O_CREAT | O_TRUNC;
>    code = open("open.tst",mode,S_IREAD|S_IWRITE);

You need to add either O_WRONLY or O_RDWR to the bits in `mode'.
Without them, when the file already exists, it is open in read-only
mode, so when `open' tries to truncate it, DOS fails the call.

It is usually a good idea to examine the value of the variable `errno'
when something like this happens.  If your program called `perror'
library function to print a human-readable description of `errno', you
would have seen "Access denied", which might have provided an
important hint as to what's going on.

>    it works with TC, lcc, gcc 2.8.1

Buggy programs can have different effect with different compilers.  
Personally, I feel safer with a library which fails a call then with one 
which silently lets me overwrite read-only files.

> To reply, change in address: no -> khe, scn <- spam

Please in the future use a real address if you want replies by direct 
email.  People who offer help on this news group have too much messages 
to reply to, and cannot afford editing anti-spammed addresses.  You 
are annoying the very people whom you asked for help.  This is IMHO
impolite.

- Raw text -


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