www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/23/18:20:49

X-Sender: dlanor AT mail DOT dds DOT nl
Message-Id: <l03130301b36e2c8c8e1e@[145.98.116.154]>
Mime-Version: 1.0
Date: Mon, 24 May 1999 00:18:04 +0200
To: djgpp AT delorie DOT com
From: Dlanor Blytkerchan <dlanor AT dds DOT nl>
Subject: freopen()
Reply-To: djgpp AT delorie DOT com

in an ANSI C program, I am attempting to create and open a read/write
binary file as follows:
I use fopen() to open the file in mode "ab". This should leave the file
alone if it already exists;
After this, I use freopen() to open the same file in mode "rab+", which -
to my knowledge, should allow me complete read/write access to the newly
created file.
Here's the prob: this works fine if the file already exists: I get the
access i wanted in the first place. If the file did not exist in the
beginning, the file is created but when I attempt to write I get an ENOENT
error, which seems odd to me, as the file has just been created.
My question: is the method I am using just too slick for DJGPP, is it an
error in my warped mind, or is there something really wrong here?
Here's an overview in code-form:

FILE *filename;

filename = fopen("foo", "ab");
if ((filename = freopen("foo", "rab+", filename)) == NULL) {
  perror("foo");
} // if

The reason I'm doing it like this in the first place, is that, though a in
the mode should create the file if it isn't there, rab+ results in ENOENT
if the file isn't there. This _only_ produces an error when, immediatly
after this operation, I try to write.

If anyone can point out my mistake - or GCCs - I'd be much obliged..

Greetz!

Dlanor

====================================================================
*    Dlanor Blytkerchan                                 * * * *    *
*    <dlanor AT dds DOT nl>                                     | | |     *
*    RLSystems software & support                       \_/-\_/    *
--------------------------------------------------------------------
*    Sites by Dlanor Blytkerchan you should visit:                 *
*    The Hazardous Domain:                                         *
*                                <http://huizen.dds.nl/~dlanor>    *
*    Including:                                                    *
*    - The Hazardous Area:                VGA Planets game site    *
*    - The Catacombes:                 VGA Planets support site    *
*    - The TKon Empire:              Rulers of The Echo Cluster    *
*    - The Insatiables:          an undefeated VGA Planets team    *
*    and:                                                          *
*    - The RLSystems main page:           miscelanious software    *
*    - The Third Domain:                 Dlanor's personal site    *
*                                                                  *
*    The Hazardous Forum - Bulletin & chat                         *
*                           <http://www.delphi.com/blytkerchan>    *
- - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - -
*    Other sites you should visit:                                 *
*    The Holodeck: a VGA Planets site by Andrew Sartori            *
*                         <http://neelix.ruralnet.net.au/vgap/>    *
*    The Last Wave: a VGA Planets site by Alan L. Warchuck         *
*     <http://www.thelastdomain.com/alan/thelastwavevgap1.html>    *
- - - - - - - - - - - - - - - - -  - - - - - - - - - - - - - - - - -
*           These sites are on The Hazardous LinkList..            *
--------------------------------------------------------------------
*    PGP public key is available at                                *
*            <http://huizen.dds.nl/~dlanor/keyring/pubring.pgp>    *
====================================================================


- Raw text -


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