Re: File Size - Big File Size

Discussion in 'C Programming' started by Michael Tsang, Oct 4, 2009.

  1. CapCity wrote:

    > Not a terrbily accomplished C coder here. I have a small ANSI C app that
    > at some point needs to know the number of bytes in a file. I've seen a few
    > suggestions along the lines of:
    >
    > fseek(fIn, 0, SEEK_END);
    > fSize = ftell(fIn);
    >
    > Which worked great until now. We have now come across a situation where
    > the file is huge (one specific example is 4,499,692,752 bytes). Even if
    > fSize is declared as "long long", which is big enough to handle that
    > value, it is not geting the correct value. So that tells me that either
    > fseek can't get that far into the file or ftell can't report a value of
    > that size.
    >
    > Is there any way I can accomplish this for huge files? This needs to run
    > on both a windows platofrm and linux, which rules out Windows API calls.
    >
    > On a similar note - if I wanted to dump the value of a long long or long
    > double to the console using printf, what do I use as the format character?
    >
    > Thanks in advance.


    ftell returns a long, which is 64-bit on *some* machines. It's probably
    better to use ftello, which returns an off_t, instead. It's in both SUS and
    POSIX
    Michael Tsang, Oct 4, 2009
    #1
    1. Advertising

  2. Michael Tsang

    Flash Gordon Guest

    Michael Tsang wrote:
    > CapCity wrote:
    >
    >> Not a terrbily accomplished C coder here. I have a small ANSI C app that
    >> at some point needs to know the number of bytes in a file. I've seen a few
    >> suggestions along the lines of:
    >>
    >> fseek(fIn, 0, SEEK_END);
    >> fSize = ftell(fIn);
    >>
    >> Which worked great until now. We have now come across a situation where
    >> the file is huge (one specific example is 4,499,692,752 bytes). Even if
    >> fSize is declared as "long long", which is big enough to handle that
    >> value, it is not geting the correct value. So that tells me that either
    >> fseek can't get that far into the file or ftell can't report a value of
    >> that size.
    >>
    >> Is there any way I can accomplish this for huge files? This needs to run
    >> on both a windows platofrm and linux, which rules out Windows API calls.
    >>
    >> On a similar note - if I wanted to dump the value of a long long or long
    >> double to the console using printf, what do I use as the format character?
    >>
    >> Thanks in advance.

    >
    > ftell returns a long, which is 64-bit on *some* machines. It's probably
    > better to use ftello, which returns an off_t, instead. It's in both SUS and
    > POSIX


    That does not necessarily help on Windows (which the OP needs to
    support), and on nix there are better methods for determining file size.
    See Windows groups for what is available on Windows and
    comp.unix.programmer for the better solutions for Unix.
    --
    Flash Gordon
    Flash Gordon, Oct 4, 2009
    #2
    1. Advertising

  3. Michael Tsang <> writes:
    > CapCity wrote:
    >> Not a terrbily accomplished C coder here. I have a small ANSI C app that
    >> at some point needs to know the number of bytes in a file. I've seen a few
    >> suggestions along the lines of:
    >>
    >> fseek(fIn, 0, SEEK_END);
    >> fSize = ftell(fIn);

    [...]
    >
    > ftell returns a long, which is 64-bit on *some* machines. It's probably
    > better to use ftello, which returns an off_t, instead. It's in both SUS and
    > POSIX


    Using ftello restricts your program's portability to POSIX and similar
    systems. If you're doing that, you might as well use stat().

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Oct 4, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    339
    Larry I Smith
    Jun 21, 2005
  2. Shaguf
    Replies:
    0
    Views:
    346
    Shaguf
    Dec 24, 2008
  3. Shaguf
    Replies:
    0
    Views:
    443
    Shaguf
    Dec 26, 2008
  4. Shaguf
    Replies:
    0
    Views:
    229
    Shaguf
    Dec 26, 2008
  5. Shaguf
    Replies:
    0
    Views:
    211
    Shaguf
    Dec 24, 2008
Loading...

Share This Page