fwrite problems on VxWorks 5.4 - VxWorks

This is a discussion on fwrite problems on VxWorks 5.4 - VxWorks ; Hi, I'm experiencing some problems with fwrite() from ansiStdio. When calling fwrite to append fresh bytes to a location in the middle of a file, we expect that some bytes in the file will be overwritten, and the rest will ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: fwrite problems on VxWorks 5.4

  1. fwrite problems on VxWorks 5.4

    Hi,

    I'm experiencing some problems with fwrite() from ansiStdio. When
    calling fwrite to append fresh bytes to a location in the middle of a
    file, we expect that some bytes in the file will be overwritten, and
    the rest will be appended to the end of the file. What I'm seeing is
    that the call is able overwrite the existing bytes, but is unable to
    add new bytes to the file. Has anyone experienced such problems?

    Say if the file originally contains 10 bytes:

    AAAAABBBBB

    I want to write 10 bytes of 'C' starting from the middle of the file,
    such that I would get:

    AAAAACCCCCCCCCC

    However, I sometimes get:

    AAAAACCCCC

    Anyone knows why?

    TIA,
    Devon.

  2. Re: fwrite problems on VxWorks 5.4

    I would check a couple of things first:

    (1) The documentation says that "output may not be immediately
    followed by input unless you make a call to fflush(), or a file
    positioning function like fseek()" -- judging by your description it
    seems like that's an important point.

    (2) Double check that your file mode will actually allow the EOF to
    be removed and replaced.....for example stdio.h for windows says that
    only "a+" allows you to append beyond the end of file. There's a good
    likelihood the same limitation applies here....


  3. Re: fwrite problems on VxWorks 5.4

    On Sep 17, 3:27*am, devonho wrote:
    > Hi,
    >
    > I'm experiencing some problems with fwrite() from ansiStdio. When
    > calling fwrite to append fresh bytes to a location in the middle of a
    > file, we expect that some bytes in the file will be overwritten, and
    > the rest will be appended to the end of the file. What I'm seeing is
    > that the call is able overwrite the existing bytes, but is unable to
    > add new bytes to the file. Has anyone experienced such problems?
    >
    > Say if the file originally contains 10 bytes:
    >
    > AAAAABBBBB
    >
    > I want to write 10 bytes of 'C' starting from the middle of the file,
    > such that I would get:
    >
    > AAAAACCCCCCCCCC
    >
    > However, I sometimes get:
    >
    > AAAAACCCCC
    >
    > Anyone knows why?
    >
    > TIA,
    > Devon.


    You need to resize the file before you write to it. Take a look at
    ftruncate.

  4. Re: fwrite problems on VxWorks 5.4

    On Sep 22, 2:09 am, Matt Havener wrote:
    > On Sep 17, 3:27 am, devonho wrote:
    >
    >
    >
    > > Hi,

    >
    > > I'm experiencing some problems with fwrite() from ansiStdio. When
    > > calling fwrite to append fresh bytes to a location in the middle of a
    > > file, we expect that some bytes in the file will be overwritten, and
    > > the rest will be appended to the end of the file. What I'm seeing is
    > > that the call is able overwrite the existing bytes, but is unable to
    > > add new bytes to the file. Has anyone experienced such problems?

    >
    > > Say if the file originally contains 10 bytes:

    >
    > > AAAAABBBBB

    >
    > > I want to write 10 bytes of 'C' starting from the middle of the file,
    > > such that I would get:

    >
    > > AAAAACCCCCCCCCC

    >
    > > However, I sometimes get:

    >
    > > AAAAACCCCC

    >
    > > Anyone knows why?

    >
    > > TIA,
    > > Devon.

    >
    > You need to resize the file before you write to it. Take a look at
    > ftruncate.


    Andersod, Matt, thanks for your replies. The file was opened in "r+b"
    mode. Even though that is so, I've not had any problems appending data
    to the end of the files using this method (or am I wrong?). Is
    enlarging the file (using ftruncate or otherwise) absolutely
    necessary?

    Thanks,
    Devon.

+ Reply to Thread