c++ file i/o

Copy of a posting on the neutrino group.

Anyone here got any ideas on this?


Hi

Any idea why the following C++ code won’t create a new file ‘err_log.txt’ if
it doesn’t already exist in the specified directory?
If I ‘touch’ a file there it works fine, but if the file doesn’t already
exist, is_open returns null.

I’m using Codewarrior IDE with Neutrino 2 (patch B) by the way.

I’ve compiled the same code on borland and run it on the pc and it works
fine (creates a file and writes err_msg to it).

Regards

Jim

void CErrorLog::WriteErrLogMsg (string err_msg)
{

fstream fileio;

fileio.open("//diskonchip//err_log//err_log.txt", ios::in | ios::out );

if (!fileio.is_open())
{
printf(“couldn’t open file\n”);
}
else
{
fileio<< “testing a file” <<endl;
fileio.close();
printf(“success\n”);
}
}

Hmmmm - discovered that its the ios::in mode option thats stopping it from
working - if I want to have append as well i.e.

fileio.open("//diskonchip//err_log//err_log.txt", ios::out | ios::app); this
works fine but if I add |ios::in the problem occurs which is wrong.

Regarding the constructor : apparently the fstream::open() mode setting is
compiler dependant so thats why I specified it explicitly.

Can anyone recreate and confirm this - should be v. easy to…

Ladida

Jim


Jim Atkins wrote in message <8ra241$qp$2@inn.qnx.com>…

Copy of a posting on the neutrino group.

Anyone here got any ideas on this?


Hi

Any idea why the following C++ code won’t create a new file ‘err_log.txt’
if
it doesn’t already exist in the specified directory?
If I ‘touch’ a file there it works fine, but if the file doesn’t already
exist, is_open returns null.

I’m using Codewarrior IDE with Neutrino 2 (patch B) by the way.

I’ve compiled the same code on borland and run it on the pc and it works
fine (creates a file and writes err_msg to it).

Regards

Jim

void CErrorLog::WriteErrLogMsg (string err_msg)
{

fstream fileio;

fileio.open("//diskonchip//err_log//err_log.txt", ios::in | ios::out );

if (!fileio.is_open())
{
printf(“couldn’t open file\n”);
}
else
{
fileio<< “testing a file” <<endl;
fileio.close();
printf(“success\n”);
}
}
\

no clues anyone?

Jim Atkins <jamesa@tsd.serco.com> wrote:

no clues anyone?

We’re looking into this. The Codewarrior product uses a different
C++ lib to the QNX RTP (MSL vs GNU), so it’s not reproduceable
on an RTP system.

Also, I notice you seem to be using a disk on chip. Does it work
differently on an hard disk, or NFS path?


cburgess@qnx.com

Hmmm - I can’t try it on a hard disk as the target platform doesn’t have one
but I have a CIFS network connection so I’ll try that…

Tried it and Yep it acts the same when trying to create the error log file
on my host machines hard drive using the CIFS connection.

I’d be grateful for any progress you have with this…


Colin Burgess wrote in message <8rveg8$aml$3@nntp.qnx.com>…

Jim Atkins <> jamesa@tsd.serco.com> > wrote:
no clues anyone?

We’re looking into this. The Codewarrior product uses a different
C++ lib to the QNX RTP (MSL vs GNU), so it’s not reproduceable
on an RTP system.

Also, I notice you seem to be using a disk on chip. Does it work
differently on an hard disk, or NFS path?


cburgess@qnx.com

Jim Atkins <jamesa@tsd.serco.com> wrote:

Hmmm - I can’t try it on a hard disk as the target platform doesn’t have one
but I have a CIFS network connection so I’ll try that…

Tried it and Yep it acts the same when trying to create the error log file
on my host machines hard drive using the CIFS connection.

I’d be grateful for any progress you have with this…

We tried this out, and you’re right, we see the same behaviour.
We’ll report it to Metrowerks…


Colin Burgess wrote in message <8rveg8$aml$> 3@nntp.qnx.com> >…
Jim Atkins <> jamesa@tsd.serco.com> > wrote:
no clues anyone?

We’re looking into this. The Codewarrior product uses a different
C++ lib to the QNX RTP (MSL vs GNU), so it’s not reproduceable
on an RTP system.

Also, I notice you seem to be using a disk on chip. Does it work
differently on an hard disk, or NFS path?


cburgess@qnx.com


cburgess@qnx.com

Is there still a plan to release Metrowerks Codewarrior using their
compiler/linker rather than GNU’s?

Jim Atkins <jamesa@tsd.serco.com> wrote:

Is there still a plan to release Metrowerks Codewarrior using their
compiler/linker rather than GNU’s?

Not to my knowledge.


cburgess@qnx.com

Hmmmm - I think I need to chat to the marketing guys then…


Colin Burgess wrote in message <8s20om$r4h$1@nntp.qnx.com>…

Jim Atkins <> jamesa@tsd.serco.com> > wrote:
Is there still a plan to release Metrowerks Codewarrior using their
compiler/linker rather than GNU’s?

Not to my knowledge.


cburgess@qnx.com

Here’s the response from Metrowerks…


This is standard behavior. The open mode “in | out” is equivalent to the
C open mode “r+”. And in C, any mode that starts with “r” won’t open
unless the file already exists.

Perhaps you are looking for “in | out | trunc” which is equivalent to
“w+”. This will truncate to zero length or create text file for update.

Colin Burgess <cburgess@qnx.com> wrote:

Jim Atkins <> jamesa@tsd.serco.com> > wrote:
Hmmm - I can’t try it on a hard disk as the target platform doesn’t have one
but I have a CIFS network connection so I’ll try that…

Tried it and Yep it acts the same when trying to create the error log file
on my host machines hard drive using the CIFS connection.

I’d be grateful for any progress you have with this…

We tried this out, and you’re right, we see the same behaviour.
We’ll report it to Metrowerks…



Colin Burgess wrote in message <8rveg8$aml$> 3@nntp.qnx.com> >…
Jim Atkins <> jamesa@tsd.serco.com> > wrote:
no clues anyone?

We’re looking into this. The Codewarrior product uses a different
C++ lib to the QNX RTP (MSL vs GNU), so it’s not reproduceable
on an RTP system.

Also, I notice you seem to be using a disk on chip. Does it work
differently on an hard disk, or NFS path?


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com

Hmmm, my first posting didn’t come through, sorry if this is a duplicate…

Here’s what Metrowerks had to say…


This is standard behavior. The open mode “in | out” is equivalent to the
C open mode “r+”. And in C, any mode that starts with “r” won’t open
unless the file already exists.

Perhaps you are looking for “in | out | trunc” which is equivalent to
“w+”. This will truncate to zero length or create text file for update.

Colin Burgess <cburgess@qnx.com> wrote:

Jim Atkins <> jamesa@tsd.serco.com> > wrote:
Hmmm - I can’t try it on a hard disk as the target platform doesn’t have one
but I have a CIFS network connection so I’ll try that…

Tried it and Yep it acts the same when trying to create the error log file
on my host machines hard drive using the CIFS connection.

I’d be grateful for any progress you have with this…

We tried this out, and you’re right, we see the same behaviour.
We’ll report it to Metrowerks…



Colin Burgess wrote in message <8rveg8$aml$> 3@nntp.qnx.com> >…
Jim Atkins <> jamesa@tsd.serco.com> > wrote:
no clues anyone?

We’re looking into this. The Codewarrior product uses a different
C++ lib to the QNX RTP (MSL vs GNU), so it’s not reproduceable
on an RTP system.

Also, I notice you seem to be using a disk on chip. Does it work
differently on an hard disk, or NFS path?


cburgess@qnx.com


cburgess@qnx.com


cburgess@qnx.com

No - what I really want is in|out|app (the equivalent of a+ in c file
o) - as I want to build up an error log file not scrub over it every time I
write to it. Perhaps I’ll try just app… (but then how dow I know if its
read/write or just write only?)

Sorry, this could just my ignorance on my part I suppose as I’m quite new to
c++, but:

If its standard behaviour how come it all works fine compiled under borland
running on a pc? What does it do compiled using RTP’s GNU C++ library ? Is
it the same? (I can’t try it as I don’t have RTP)

Regards

Jim

nuts - app doesn’t work as the equivalent of a+.

Looks like I’ll have to initially open it one way then in future check if it
exists and then open it a different way to append to it.

On reflection I’ll just write my own wrapper for using standard c file io
and use a+ - its easier…

Ta for your help

Jim


Jim Atkins wrote in message <8s3pmu$80k$1@inn.qnx.com>…

No - what I really want is in|out|app (the equivalent of a+ in c file
o) - as I want to build up an error log file not scrub over it every time
I
write to it. Perhaps I’ll try just app… (but then how dow I know if its
read/write or just write only?)

Sorry, this could just my ignorance on my part I suppose as I’m quite new
to
c++, but:

If its standard behaviour how come it all works fine compiled under borland
running on a pc? What does it do compiled using RTP’s GNU C++ library ? Is
it the same? (I can’t try it as I don’t have RTP)

Regards

Jim

I’ve forwarded your comments to Metrowerks. Hopefully they will have
some constructive comments… :slight_smile:

Jim Atkins <jamesa@tsd.serco.com> wrote:

nuts - app doesn’t work as the equivalent of a+.

Looks like I’ll have to initially open it one way then in future check if it
exists and then open it a different way to append to it.

On reflection I’ll just write my own wrapper for using standard c file io
and use a+ - its easier…

Ta for your help

Jim



Jim Atkins wrote in message <8s3pmu$80k$> 1@inn.qnx.com> >…
No - what I really want is in|out|app (the equivalent of a+ in c file
o) - as I want to build up an error log file not scrub over it every time
I
write to it. Perhaps I’ll try just app… (but then how dow I know if its
read/write or just write only?)

Sorry, this could just my ignorance on my part I suppose as I’m quite new
to
c++, but:

If its standard behaviour how come it all works fine compiled under borland
running on a pc? What does it do compiled using RTP’s GNU C++ library ? Is
it the same? (I can’t try it as I don’t have RTP)

Regards

Jim
\


cburgess@qnx.com