[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

stat.st_size: How does it work?

Peter Lauren

4/22/2011 10:27:00 PM

Can anyone tell me roughly how stat.st_size works in order to get the
size of the file? Does it read through the file and count the number
of bytes? Would this take time for a super large file?

Thanks,
Peter.
6 Answers

Lew Pitcher

4/22/2011 11:39:00 PM

0

On Apr 22, 6:27 pm, Peter Lauren <peterdlau...@gmail.com> wrote:
> Can anyone tell me roughly how stat.st_size works in order to get the
> size of the file?  Does it read through the file and count the number
> of bytes?  Would this take time for a super large file?

IIRC, st_size is maintained as the file is written. With each write()
call, st_size is incremented by the number of bytes written.

So, when you stat() a file, st_size is just set, not computed.

HTH

Lew Pitcher

4/22/2011 11:42:00 PM

0

Oops... I didn't notice that this was comp.lang.c
Sorry for the off-topic reply.

To the OP: stat.st_size is AFAICR not part of the C standard.
Consequently, your question (and my reply) is off-topic here.

You really should ask in one of the forums dedicated to your operating
system (presumably a POSIX/SUS compatable OS such as BSD or Linux)

China Blue Veins

4/22/2011 11:56:00 PM

0

In article <f9e5bb32-545e-41a7-8e44-4489e7790a1f@y31g2000vbp.googlegroups.com>,
Peter Lauren <peterdlauren@gmail.com> wrote:

> Can anyone tell me roughly how stat.st_size works in order to get the
> size of the file? Does it read through the file and count the number
> of bytes? Would this take time for a super large file?

Implementation dependent. Also device dependent: you have to scan mag tape to
find out its length.

--
Damn the living - It's a lovely life. I'm whoever you want me to be.
Silver silverware - Where is the love? At least I can stay in character.
Oval swimming pool - Where is the love? Annoying Usenet one post at a time.
Damn the living - It's a lovely life. Why does Harmony have blue veins?

Seebs

4/23/2011 1:12:00 AM

0

On 2011-04-22, Peter Lauren <peterdlauren@gmail.com> wrote:
> Can anyone tell me roughly how stat.st_size works in order to get the
> size of the file? Does it read through the file and count the number
> of bytes? Would this take time for a super large file?

This has nothing at all to do with C, and a whole lot to do with whatever
programming environment you're looking at.

Just an idle thought, though: If you had to read through a file and
count bytes to know how large it was, how exactly would directory listings
work? I'd guess that filesystems probably track that kind of information
internally.

-s
p.s.: There is an eerie similarity between this "st_size" member which
supposedly contains the "size" of a file, and one of the components of the
Unix "struct stat" data object, in which case perhaps a Unix newsgroup?
Remember that the system call will behave the same way if you access it
from perl, or Ruby, or FORTRAN, or anything else; it's a feature of the
operating system, not of th eprogramming language.
--
Copyright 2011, all wrongs reversed. Peter Seebach / usenet-nospam@seebs.net
http://www.seeb... <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/...(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.

luserXtrog

4/25/2011 4:04:00 AM

0

On Apr 22, 6:56 pm, China Blue Veins <chine.b...@yahoo.com> wrote:
> In article <f9e5bb32-545e-41a7-8e44-4489e7790...@y31g2000vbp.googlegroups..com>,
>  Peter Lauren <peterdlau...@gmail.com> wrote:
>
> > Can anyone tell me roughly how stat.st_size works in order to get the
> > size of the file?  Does it read through the file and count the number
> > of bytes?  Would this take time for a super large file?
>
> Implementation dependent. Also device dependent: you have to scan mag tape to
> find out its length.
>

But for paper tape you could use a camera and trigonometry!

Kenneth Brody

4/25/2011 6:35:00 PM

0

On 4/25/2011 12:04 AM, luser- -droog wrote:
> On Apr 22, 6:56 pm, China Blue Veins<chine.b...@yahoo.com> wrote:
>> In article<f9e5bb32-545e-41a7-8e44-4489e7790...@y31g2000vbp.googlegroups..com>,
>> Peter Lauren<peterdlau...@gmail.com> wrote:
>>
>>> Can anyone tell me roughly how stat.st_size works in order to get the
>>> size of the file? Does it read through the file and count the number
>>> of bytes? Would this take time for a super large file?
>>
>> Implementation dependent. Also device dependent: you have to scan mag tape to
>> find out its length.

Well, as mentioned else-thread, the stat() system call is POSIX, and not
part of the C standard. How it works is "magic" as far as any application
using it is concerned.

> But for paper tape you could use a camera and trigonometry!

It depends... When I used paper tape (yes, I really did), you could have
NUL leader and header columns, and you also had the option of
all-holes-punched columns to allow for fan-fold storage, rather than rolled.
Would these count to the "file" size?

:-)

--
Kenneth Brody