home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / unix / question / 13349 < prev    next >
Encoding:
Text File  |  1992-11-13  |  2.0 KB  |  52 lines

  1. Newsgroups: comp.unix.questions
  2. 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
  3. From: etxmesa@eos.ericsson.se (Michael Salmon)
  4. Subject: Re: Getting a file's size with the FILE data structure
  5. Message-ID: <1992Nov13.082144.13575@ericsson.se>
  6. Sender: news@ericsson.se
  7. Nntp-Posting-Host: eos6c02.ericsson.se
  8. Reply-To: etxmesa@eos.ericsson.se (Michael Salmon)
  9. Organization: Ericsson Telecom AB
  10. References:  <l=r19z_@rpi.edu>
  11. Date: Fri, 13 Nov 1992 08:21:44 GMT
  12. Lines: 38
  13.  
  14. In article <l=r19z_@rpi.edu>, 
  15. cecchinr@hornsby.cs.rpi.edu (Ron Cecchini) writes:
  16. |> Hi again,
  17. |> 
  18. |>  I found that you can use the FILE ds to get a file's size.  However,
  19. |> there seems to be a glitch with it.  For one, the data structure is
  20. |> NOT initialized after the fopen().  So, thats no good.  And you can't try
  21. |> to fseek() to the beginning and look at ->_cnt.  What I found you have to do
  22. |> is: fgets() a line from the file and *THEN* fseek() back to the beginning
  23. |> of the file.  *NOW* ->_cnt contains the size of the file.
  24. |> 
  25. |> Ron
  26. |> 
  27. |> p.s. I have received info on using the stat() command to also get the info.
  28. |> 
  29.  
  30. You don't mention which system you are using and so perhaps this works
  31. for you but I doubt that it is portable. ->_cnt is the number of
  32. characters left in the buffer, for reads this is the number of
  33. characters last read from the file minus the number of characters read
  34. from the buffer. Hence when you use fgets() (getc is equally good) then
  35. fseek() to the beginning you have filled the buffer, then reset the
  36. pointers and _cnt to the beginning of the buffer. ->_cnt will hence
  37. contain the file size if and only if the file is smaller than the
  38. buffer. All of the above applies only if stdio uses read() and write(),
  39. systems using mmap() will exhibit different characteristics and your
  40. observations are then most likely correct.
  41.  
  42. -- 
  43.  
  44. Michael Salmon
  45.  
  46. #include    <standard.disclaimer>
  47. #include    <witty.saying>
  48. #include    <fancy.pseudo.graphics>
  49.  
  50. Ericsson Telecom AB
  51. Stockholm
  52.