home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!taumet!steve
- From: steve@taumet.com (Steve Clamage)
- Subject: Re: Finding length of file?
- Message-ID: <1992Nov9.191316.11833@taumet.com>
- Organization: TauMetric Corporation
- References: <BxF36F.CwA@ux1.cso.uiuc.edu>
- Date: Mon, 9 Nov 1992 19:13:16 GMT
- Lines: 30
-
- ceblair@ux1.cso.uiuc.edu (Charles Blair) writes:
-
-
- > Sorry if this is an FAQ, I couldn't find it in any of the current
- >postings.
-
- > I have created a file for reading using fopen. Is there a simple
- >quick way to find out how many bytes there are until EOF? I would
- >prefer something that is part of the standard, which I think rules
- >out the read command. I thought I might be able to do this using
- >p -> cnt for p a pointer to FILE, but that didn't work.
-
- The only Standard-conforming and portable way to find out how many
- bytes are in a file is to open the file (or seek to its beginning),
- and read bytes until EOF, keeping track of how many you read.
-
- Because of the diversity of file systems, you are not guaranteed in
- either text or binary mode that what you wrote to a file is precisely
- what is in the file. That is, for example, lines in a text file might
- have more or fewer trailing blanks than you wrote, and a binary file
- might have more or fewer trailing nulls than you wrote. There are
- other issues as well.
-
- C implementations often provide functions which tell you many things
- about files, including size. For example, stat() and fstat() are
- common functions, but not part of the C Standard.
- --
-
- Steve Clamage, TauMetric Corp, steve@taumet.com
- Vice Chair, ANSI C++ Committee, X3J16
-