Re: [NEWBIE] File size

From: George Greer (greerga@circlemud.org)
Date: 05/07/00


On Mon, 8 May 2000, Jarratt Davis wrote:

>Well although this sounds like a newbie question, Im not exactly a newbie
>coder :)  What Im trying to work out is how can I find out the size of a
>file that Im opening? And how can I do this without using an OS specific
>call?  Ive written my own ASCII system for my MUD, but want to add buffers
>- and rather than sticking with staic sized buffers I would like to have
>the buffers be related to the size of the file that is being opened (for
>reading not writing).

struct stat statbuf;
int fd;
off_t size;

fd = open("filename", O_RDONLY);
fstat(fd, &statbuf);
size = statbuf.st_size;
close(fd);

Granted it is a Unix function, but MSVC supports it.  If you don't want to
do it that way (because you use stdio, for example), then you'll have to
look it up in the foundation classes or some other nonsense.  Not that MSVC
supporting it doesn't require you to include all sort of funny headers like
'io.h'

--
George Greer
greerga@circlemud.org


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 04/10/01 PDT