Mail Archives: djgpp/1998/04/21/06:34:40
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 -