Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

create new file

5 views
Skip to first unread message

kerr...@w3.to

unread,
Mar 10, 2013, 3:00:38 AM3/10/13
to
I have the following program:

C:\devel\pdos\src>type writfil.c
#include <stdio.h>

int main(void)
{
FILE *fq;

printf("opening file\n");
fq = fopen("zzout.txt", "w");
printf("fq is %p\n", fq);
return (0);
}

And I compiled it with tcc++ 1.01 and then
ran it under my own OS (PDOS) and was
surprised to see that after printing
"opening file" there was an MSDOS
INT 21h ah=3d call.

I was expecting ah=3c

http://www.ctyme.com/intr/int-21.htm

Is it normal for a C runtime to treat an
fopen of "w" as "check to see if there is
an existing file before creating one? I
would have expected that MSDOS took care
of that, no need for the C runtime library
to care.

Thanks. Paul.

kerr...@w3.to

unread,
Mar 10, 2013, 3:48:17 AM3/10/13
to
On Sunday, March 10, 2013 6:00:38 PM UTC+11, kerr...@w3.to wrote:

>
> I was expecting ah=3c

A bit more information. There is a AH=43h call
first (get file attributes), and once I changed
PDOS to return a failure on that call, I did
get a 3C call.

BFN. Paul.

R.Wieser

unread,
Mar 10, 2013, 11:44:31 AM3/10/13
to
Hello Paul,

Its quite possible the C library does some extra/extensive checking on that
filename. Possible reason ? That function can most likely be used to open
a few things more than just a disk-file. Console in and output as well as
RS232 comes to mind. Depending on what you open diferent subsequent actions
need to be taken.

You could tell your compiler to generate (an intermediate) Assembler-file
too, and see what it does after the (trying to) open the existing file (int
21h, AH=3Dh).

Regards,
Rudy Wieser


-- Origional message
<kerr...@w3.to> schreef in berichtnieuws
ef7511d8-dd9c-4b11...@googlegroups.com...

Rod Pemberton

unread,
Mar 11, 2013, 3:53:18 AM3/11/13
to
<kerr...@w3.to> wrote in message
news:75580a0d-15e3-41da...@googlegroups.com...

> Is it normal for a C runtime to treat an
> fopen of "w" as "check to see if there is
> an existing file before creating one?

According to Harbison and Steele's "C: A Reference Manual", 3rd
edition, "w" is supposed to either create a new file or truncate
an existing file. "w+" truncates too. "wb" is not listed.

ISO C99 says "w+" is to "truncate to zero length or create text
file for update" in 7.19.5.3 "The fopen function" subsection 3.
"w", "w+", and "wb" all truncate.

ISTM, that the "truncation" feature of "w", "wb", and "w+", would
imply "w" is supposed to check the existence of the file in order
to delete it if it exists, i.e., "truncate"...

So, I'd say: "Yes." Although, I've not actually tested any C
libraries to check what they actually do for this situation.

FYI, current ISO C "rough draft" specifications are available
online. And, there is comp.lang.c if you dare go there...


Rod Pemberton


0 new messages