473,327 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Help ! how to get a file size larger than 2G?

zou
there is a file which is very large,

we can use stat to get a file size(<2G),
struct stat buf;
stat("file", &buf);
long s=(long)stat.st_size;

but stat::st_size is type of off_t(typedef long),
so how about a file larger than 2G?

many thanks~
Sep 30 '07 #1
12 4065
zou wrote:
there is a file which is very large,

we can use stat to get a file size(<2G),
struct stat buf;
stat("file", &buf);
long s=(long)stat.st_size;

but stat::st_size is type of off_t(typedef long),
so how about a file larger than 2G?
You'll have to investigate the options provided by your platform. Standard C
itself specifies no functions to get the size of a "file." The only fully
portable method is to read through the file and keep count, and even then,
it's size "on disk" might be different to the size calculated by reading
it.

You also seem to be using C++. If so, then the appropriate group is
comp.lang.c++.

Sep 30 '07 #2
zou wrote:
there is a file which is very large,

we can use stat to get a file size(<2G),
struct stat buf;
stat("file", &buf);
long s=(long)stat.st_size;

but stat::st_size is type of off_t(typedef long),
so how about a file larger than 2G?
You are as off topic here as you were in c.l.c++, try comp.unix.programmer.

--
Ian Collins.
Sep 30 '07 #3
zou wrote:
>
there is a file which is very large,

we can use stat to get a file size(<2G),
struct stat buf;
stat("file", &buf);
long s=(long)stat.st_size;

but stat::st_size is type of off_t(typedef long),
so how about a file larger than 2G?
stat and off_t are not part of standard C and thus off-topic here.
Find a newsgroup dealing with your system, possibly
comp.unix.programmer.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>

--
Posted via a free Usenet account from http://www.teranews.com

Sep 30 '07 #4
On Sep 30, 1:06 pm, CBFalconer <cbfalco...@yahoo.comwrote:
zou wrote:
there is a file which is very large,
we can use stat to get a file size(<2G),
struct stat buf;
stat("file", &buf);
long s=(long)stat.st_size;
but stat::st_size is type of off_t(typedef long),
so how about a file larger than 2G?

stat and off_t are not part of standard C and thus off-topic here.
Find a newsgroup dealing with your system, possibly
comp.unix.programmer.
It looks like this function is only available to Unix systems.
I think, you can check with the man page of stat.

C version of code ;-)
Refer this link - http://www.phim.unibe.ch/comp_doc/c_...XAMPLES/stat.c

#include <sys/stat.h> /* declare the 'stat' structure */

struct stat stat_p; /* 'stat_p' is a pointer to a structure
* of type 'stat'. */

if ( -1 == stat (filename, &stat_p))
{
printf(" Error occoured attempting to stat %s\n", filename);
exit(0);
}

printf("File size is %d bytes\n", stat_p.st_size);

Karthik Balaguru

Sep 30 '07 #5
On Sep 30, 9:21 am, zou <zou...@gmail.comwrote:
there is a file which is very large,

we can use stat to get a file size(<2G),
struct stat buf;
stat("file", &buf);
long s=(long)stat.st_size;

but stat::st_size is type of off_t(typedef long),
so how about a file larger than 2G?

many thanks~
What kind of compilers are you using?

I once did so in Microsoft Visual C++ 6.0. According to GNU C library,
there should be some functions like stat64/fstat64, but I cannot get
it work in Cygwin. I guess that stat64 would work in Linux/Unix.

Regards,
Tian

Sep 30 '07 #6
"karthikbalaguru" <ka***************@gmail.coma écrit dans le message de
news: 11*********************@r29g2000hsg.googlegroups.c om...
On Sep 30, 1:06 pm, CBFalconer <cbfalco...@yahoo.comwrote:
>zou wrote:
there is a file which is very large,
we can use stat to get a file size(<2G),
struct stat buf;
stat("file", &buf);
long s=(long)stat.st_size;
but stat::st_size is type of off_t(typedef long),
so how about a file larger than 2G?

stat and off_t are not part of standard C and thus off-topic here.
Find a newsgroup dealing with your system, possibly
comp.unix.programmer.

It looks like this function is only available to Unix systems.
I think, you can check with the man page of stat.
Wrong, it is available on a lot of non-Unix systems: cygwin, Windows (albeit
renamed to _stat)
C version of code ;-)
Refer this link -
http://www.phim.unibe.ch/comp_doc/c_...XAMPLES/stat.c
That code looks pretty old and bogus
>
#include <sys/stat.h/* declare the 'stat' structure */
These are possibly also needed:
#include <sys/types.h>
#include <unistd.h>
>
struct stat stat_p; /* 'stat_p' is a pointer to a structure
* of type 'stat'. */
wrong, stat_p is a struct with an utterly misleading name

if ( -1 == stat (filename, &stat_p))
This style looks childish to me.
{
printf(" Error occoured attempting to stat %s\n", filename);
More typos, plus errors should go to stderr.
exit(0);
Better exit with EXIT_FAILURE if this is an error
}

printf("File size is %d bytes\n", stat_p.st_size);
stat_p.st_size is not an int.
It is an off_t: possibly a long or a long long.
It would be safer to write:

printf("File size is %lld bytes\n", (long long)stat_p.st_size);

Your post was off topic, and a correct answer had already been given with an
appropriate newsgroup to query.
To make things worse, your anwser is misleading and erroneous.
Please refrain from posting answers on topics you do not master, especially
when the question is off topic already.

--
Chqrlie.
Sep 30 '07 #7
karthikbalaguru wrote:
On Sep 30, 1:06 pm, CBFalconer <cbfalco...@yahoo.comwrote:
>zou wrote:
there is a file which is very large,
we can use stat to get a file size(<2G),
struct stat buf;
stat("file", &buf);
long s=(long)stat.st_size;
but stat::st_size is type of off_t(typedef long),
so how about a file larger than 2G?

stat and off_t are not part of standard C and thus off-topic here.
Find a newsgroup dealing with your system, possibly
comp.unix.programmer.

It looks like this function is only available to Unix systems.
I think, you can check with the man page of stat.

C version of code ;-)
Refer this link -
http://www.phim.unibe.ch/comp_doc/c_...XAMPLES/stat.c

#include <sys/stat.h /* declare the 'stat' structure */

struct stat stat_p; /* 'stat_p' is a pointer to a structure
* of type 'stat'. */

if ( -1 == stat (filename, &stat_p))
{
printf(" Error occoured attempting to stat %s\n", filename);
exit(0);
}

printf("File size is %d bytes\n", stat_p.st_size);
Please attempt, wherever possible, to provide correct and compilable code.
The above code fragment, besides being uncompilable, is also not correct,
in that it invokes undefined behaviour in at least one place.

Sep 30 '07 #8
In article <fd*********@news.yaako.com>, zou <zo****@gmail.comwrote:
but stat::st_size is type of off_t(typedef long),
so how about a file larger than 2G?
I suppose by "stat::st_size" you mean the st_size field of the stat
structure. Note that stat() isn't a standard C function, but a unix
one which has made its way into some other systems.

Some systems have a symbol you can #define to make off_t be a 64-bit
type on a system where it is usually 32 bits. It appears to be
__USE_FILE_OFFSET64 on a Linux system here, but I have no experience
of using it so I recommend you ask in a group more specific to your
system.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Sep 30 '07 #9
On Sun, 30 Sep 2007 17:51:08 +0530, santosh
<sa*********@gmail.comwrote:
>karthikbalaguru wrote:
>On Sep 30, 1:06 pm, CBFalconer <cbfalco...@yahoo.comwrote:
>>zou wrote:

there is a file which is very large,

we can use stat to get a file size(<2G),
struct stat buf;
stat("file", &buf);
long s=(long)stat.st_size;

but stat::st_size is type of off_t(typedef long),
so how about a file larger than 2G?

stat and off_t are not part of standard C and thus off-topic here.
Find a newsgroup dealing with your system, possibly
comp.unix.programmer.

It looks like this function is only available to Unix systems.
I think, you can check with the man page of stat.

C version of code ;-)
Refer this link -
http://www.phim.unibe.ch/comp_doc/c_...XAMPLES/stat.c

#include <sys/stat.h /* declare the 'stat' structure */

struct stat stat_p; /* 'stat_p' is a pointer to a structure
* of type 'stat'. */

if ( -1 == stat (filename, &stat_p))
{
printf(" Error occoured attempting to stat %s\n", filename);
exit(0);
}

printf("File size is %d bytes\n", stat_p.st_size);

Please attempt, wherever possible, to provide correct and compilable code.
The above code fragment, besides being uncompilable, is also not correct,
in that it invokes undefined behaviour in at least one place.
You've misread the posting.
Richard Harter, cr*@tiac.net
http://home.tiac.net/~cri, http://www.varinoma.com
But the rhetoric of holistic harmony can generate into a kind of
dotty, Prince Charles-style mysticism. -- Richard Dawkins
Sep 30 '07 #10
santosh <sa*********@gmail.comwrites:
karthikbalaguru wrote:
>On Sep 30, 1:06 pm, CBFalconer <cbfalco...@yahoo.comwrote:
>>zou wrote:

there is a file which is very large,

we can use stat to get a file size(<2G),
struct stat buf;
stat("file", &buf);
long s=(long)stat.st_size;

but stat::st_size is type of off_t(typedef long),
so how about a file larger than 2G?

stat and off_t are not part of standard C and thus off-topic here.
Find a newsgroup dealing with your system, possibly
comp.unix.programmer.

It looks like this function is only available to Unix systems.
I think, you can check with the man page of stat.

C version of code ;-)
Refer this link -
http://www.phim.unibe.ch/comp_doc/c_...XAMPLES/stat.c

#include <sys/stat.h /* declare the 'stat' structure */

struct stat stat_p; /* 'stat_p' is a pointer to a structure
* of type 'stat'. */

if ( -1 == stat (filename, &stat_p))
{
printf(" Error occoured attempting to stat %s\n", filename);
exit(0);
}

printf("File size is %d bytes\n", stat_p.st_size);

Please attempt, wherever possible, to provide correct and compilable code.
The above code fragment, besides being uncompilable, is also not correct,
in that it invokes undefined behaviour in at least one place.
Since the undefined behaviour is nothing to so with stat, as such,
possibly you could explain? Surely not all "samples" that people post
where they are having difficulties need to be sanitised?!?!? At first
glance all I see really wrong is the comment about stat_p being a pointer. It
isn't. And of course the lack of an include for printf.

Sep 30 '07 #11
"Richard" <rg****@gmail.comschrieb im Newsbeitrag
news:34************@news.individual.net...
santosh <sa*********@gmail.comwrites:
>karthikbalaguru wrote:
>>On Sep 30, 1:06 pm, CBFalconer <cbfalco...@yahoo.comwrote:
zou wrote:

there is a file which is very large,

we can use stat to get a file size(<2G),
struct stat buf;
stat("file", &buf);
long s=(long)stat.st_size;

but stat::st_size is type of off_t(typedef long),
so how about a file larger than 2G?

stat and off_t are not part of standard C and thus off-topic here.
Find a newsgroup dealing with your system, possibly
comp.unix.programmer.
It looks like this function is only available to Unix systems.
I think, you can check with the man page of stat.

C version of code ;-)
Refer this link -
http://www.phim.unibe.ch/comp_doc/c_...XAMPLES/stat.c

#include <sys/stat.h /* declare the 'stat' structure */

struct stat stat_p; /* 'stat_p' is a pointer to a structure
* of type 'stat'. */

if ( -1 == stat (filename, &stat_p))
{
printf(" Error occoured attempting to stat %s\n", filename);
exit(0);
}

printf("File size is %d bytes\n", stat_p.st_size);

Please attempt, wherever possible, to provide correct and compilable
code.
The above code fragment, besides being uncompilable, is also not correct,
in that it invokes undefined behaviour in at least one place.

Since the undefined behaviour is nothing to so with stat, as such,
possibly you could explain? Surely not all "samples" that people post
where they are having difficulties need to be sanitised?!?!? At first
glance all I see really wrong is the comment about stat_p being a pointer.
It
isn't. And of course the lack of an include for printf.
And exactly that missing "#include <stdio.h>" is causing undefined behaviour
(varadic function without prototype).

Bye, Jojo
Sep 30 '07 #12

"Joachim Schmitz" <no*********@schmitz-digital.dewrites:
>Since the undefined behaviour is nothing to so with stat, as such,
possibly you could explain? Surely not all "samples" that people post
where they are having difficulties need to be sanitised?!?!? At first
glance all I see really wrong is the comment about stat_p being a pointer.
It
isn't. And of course the lack of an include for printf.
And exactly that missing "#include <stdio.h>" is causing undefined behaviour
(varadic function without prototype).

Bye, Jojo
I know. hence I pointed it out. The point here is that yet again we have
"noise" shouting "OT" while not actually providing any help.
Sep 30 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: PeterB | last post by:
Hi! I am using the script below to download files, that are in a non-public directory, from my site. The "smaller files" section works for smaller files. However when the files are getting...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
12
by: LongBow | last post by:
Hello all, From doing a google serach in the newsgroups I found out that a string can't be returned from a function, but using a char* I should be able to do it. I have spent most of the day...
5
by: Claudio Grondi | last post by:
I have just started to play around with the bsddb3 module interfacing the Berkeley Database. Beside the intended database file databaseFile.bdb I see in same directory also the __db.001...
7
by: | last post by:
I was wondering if anyone can help explain this code for me <table width="<?= $TABLE_WIDTH ?>" border="0" cellspacing="0" cellpadding="0"> <?php for ($x=1; $x<=pow(2, $COLUMNS); $x++) { // open...
5
by: Jefferis NoSpamme | last post by:
Hi all, I'm trying to limit the file size of an image submission and I keep running into various problems. I've got most of it working, but I'm stumped and I have a basic question as to WHY this...
3
by: zou | last post by:
there is a file which is very large, we can use stat to get a file size(<2G), struct stat buf; stat("file", &buf); long s=(long)stat.st_size; but stat::st_size is type of off_t(typedef...
6
by: bobby | last post by:
hi group, Does the header file size or number in include(s) effect the size of executable file? In other world if i chose a large header file and include it with my source file does it increase...
4
by: rsaharia | last post by:
Hello All, I need help with this particular .pl file I picked up from http://www.veritools-usa.com/xnf2vhdl.htm What it's supposed to do is really convert an xnf file to a vhdl file. I need it for...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.