home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!spool.mu.edu!yale.edu!ira.uka.de!gmd.de!Germany.EU.net!mcsun!sunic!sics.se!eua.ericsson.se!ericom!eos.ericsson.se!etxmesa
- From: etxmesa@eos.ericsson.se (Michael Salmon)
- Subject: Re: Getting a file's size with the FILE data structure
- Message-ID: <1992Nov13.082144.13575@ericsson.se>
- Sender: news@ericsson.se
- Nntp-Posting-Host: eos6c02.ericsson.se
- Reply-To: etxmesa@eos.ericsson.se (Michael Salmon)
- Organization: Ericsson Telecom AB
- References: <l=r19z_@rpi.edu>
- Date: Fri, 13 Nov 1992 08:21:44 GMT
- Lines: 38
-
- In article <l=r19z_@rpi.edu>,
- cecchinr@hornsby.cs.rpi.edu (Ron Cecchini) writes:
- |> Hi again,
- |>
- |> I found that you can use the FILE ds to get a file's size. However,
- |> there seems to be a glitch with it. For one, the data structure is
- |> NOT initialized after the fopen(). So, thats no good. And you can't try
- |> to fseek() to the beginning and look at ->_cnt. What I found you have to do
- |> is: fgets() a line from the file and *THEN* fseek() back to the beginning
- |> of the file. *NOW* ->_cnt contains the size of the file.
- |>
- |> Ron
- |>
- |> p.s. I have received info on using the stat() command to also get the info.
- |>
-
- You don't mention which system you are using and so perhaps this works
- for you but I doubt that it is portable. ->_cnt is the number of
- characters left in the buffer, for reads this is the number of
- characters last read from the file minus the number of characters read
- from the buffer. Hence when you use fgets() (getc is equally good) then
- fseek() to the beginning you have filled the buffer, then reset the
- pointers and _cnt to the beginning of the buffer. ->_cnt will hence
- contain the file size if and only if the file is smaller than the
- buffer. All of the above applies only if stdio uses read() and write(),
- systems using mmap() will exhibit different characteristics and your
- observations are then most likely correct.
-
- --
-
- Michael Salmon
-
- #include <standard.disclaimer>
- #include <witty.saying>
- #include <fancy.pseudo.graphics>
-
- Ericsson Telecom AB
- Stockholm
-