Thread: struct stat st_blocks and st_blksize

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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.

Popular pages Recent additions subscribe to a feed