struct stat st_blocks and st_blksize

This is a discussion on struct stat st_blocks and st_blksize within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, I'm writing some code which should find the 'size' of a file in bytes, and the 'size on ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    5

    struct stat st_blocks and st_blksize

    Hi everyone,

    I'm writing some code which should find the 'size' of a file in bytes, and the 'size on disk' of the file - the size considering the wasted space considering clusters.

    This is no problem - using:

    struct stat attrib;
    stat(path.c_str(), &attrib);

    size = attrib.st_size;
    sizeOnDisk = (attrib.st_blocks * attrib.st_blksize);

    I can get the correct values. This will compile fine in g++ etc but trying to get it to compile in Borland compiler, I find that st_blocks and st_blksize are not members of struct stat.

    Is there another method I can use to get these values?

    Thanks in advance

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,687
    What does your borland manual page say about the fields returned by stat() ?
    stat() is not a portable function, and what it returns isn't portable either.


    > Is there another method I can use to get these values?
    Probably, but that depends on which of the many borland compilers there have been over the years you actually have.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21