Easiest way to get file size (unix)? 
Author Message
 Easiest way to get file size (unix)?

I have a database file (filled with structures i've used fwrite() to create.

what's the fastest way to determine the number of records in the database?
If I could get the size of the file in bytes, I could do

        filesize / sizeof(record)

but there doesn't seem to be a function in unix GCC to do this.

Turbo C on the PC has a "filelength" function that does exactly what i'm
looking for, but unix has none.

thanks in advance.
(mail replies, please!)
-john

--
-------------------------------------------------------------------------------

Boston University +============================================================
458 Beacon St     | "A world of shapes in carving lust and devouring
Boston, MA 02115  |  appetite?"
617.765.0818      |             - Blake
------------------+------------------------------------------------------------



Tue, 11 Jun 1996 16:42:51 GMT  
 Easiest way to get file size (unix)?

Quote:

>I have a database file (filled with structures i've used fwrite() to create.

>what's the fastest way to determine the number of records in the database?
>If I could get the size of the file in bytes, I could do

>        filesize / sizeof(record)

>but there doesn't seem to be a function in unix GCC to do this.

Look up stat/fstat.

Followups to comp.unix.programmer.

-----------------------------------------


-----------------------------------------



Wed, 12 Jun 1996 03:54:13 GMT  
 Easiest way to get file size (unix)?

Quote:
>I have a database file (filled with structures i've used fwrite() to create.

>what's the fastest way to determine the number of records in the database?
>If I could get the size of the file in bytes, I could do

>    filesize / sizeof(record)

>but there doesn't seem to be a function in unix GCC to do this.

The compiler is not the issue - the question is does the OS rtl's have
a function that will do the job. The answer is yes - see later.

Quote:
>Turbo C on the PC has a "filelength" function that does exactly what i'm
>looking for, but unix has none.

Do a "man stat" for a function that returns detailed information on
files.  This is, I believe, also available in Microsoft C and Borland
C, so is potentially much more portable than "filelength()".

                                                                Z

--
-------------------------------------------------------------------------
| Syed Zaeem Hosain          P. O. Box 610097            (408) 441-7021 |

-------------------------------------------------------------------------



Wed, 12 Jun 1996 06:43:38 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Check the file size and number symbols in a file using C in Unix

2. Getting ftp file file size

3. easy way of getting file summary info?

4. WTL: alternative ways of getting and instalation?

5. Other ways of getting device handler

6. Getting file permission in UNIX

7. getting the full pathname of a executable file (Unix / C)

8. Unix 2GB file size limit

9. size of UNIX files

10. Getting the File Size

11. getting the size of a file

12. getting a file's size

 

 
Powered by phpBB® Forum Software