Date: Tue, 21 Apr 1998 13:33:04 +0300 (IDT) From: Eli Zaretskii To: Andreas Kochenburger cc: djgpp AT delorie DOT com Subject: Re: Bug in djgpp 2.8.0b with open()? In-Reply-To: <353b0193.4405066@news> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk 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.