Connecting Tech Pros Worldwide Help | Site Map

Help how to get file size of larger file(>2G)?

zou
Guest
 
Posts: n/a
#1: Sep 29 '07
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?

=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
Guest
 
Posts: n/a
#2: Sep 29 '07

re: Help how to get file size of larger file(>2G)?


On 2007-09-29 11:51, zou wrote:
Quote:
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() is POSIX, not C++ so you are off topic. Further more the only
requirement I could find on off_t was that it should be a signed
integral type, so it might just as well be a long long or an int. The
type of off_t is platform dependent, so if your platform uses a 32 bit
long and off_t is a long then you can not work with files larger than 2
GiB. For more information contact your platform vendor.

--
Erik Wikström
ltcmelo
Guest
 
Posts: n/a
#3: Sep 30 '07

re: Help how to get file size of larger file(>2G)?


On Sep 29, 2:54 am, Erik Wikström <Erik-wikst...@telia.comwrote:
Quote:
On 2007-09-29 11:51, zou wrote:
>
Quote:
there is a file which is very large,
>
Quote:
we can use stat to get a file size(<2G),
struct stat buf;
stat("file", &buf);
long s=(long)stat.st_size;
>
Quote:
but stat::st_size is type of off_t(typedef long),
so how about a file larger than 2G?
>
stat() is POSIX, not C++ so you are off topic. Further more the only
requirement I could find on off_t was that it should be a signed
integral type, so it might just as well be a long long or an int. The
type of off_t is platform dependent, so if your platform uses a 32 bit
long and off_t is a long then you can not work with files larger than 2
GiB. For more information contact your platform vendor.
>
--
Erik Wikström

Hi.

If you're working with gcc, you might want to take a look at
http://www.delorie.com/gnu/docs/glibc/libc_285.html. There's a
compiler flag (_FILE_OFFSET_BITS) which allows you to work with
functions like lstat64, fstat64, and others, in 32-bit environment.

--
Leandro Melo


=?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=
Guest
 
Posts: n/a
#4: Sep 30 '07

re: Help how to get file size of larger file(>2G)?


On 2007-09-30 00:57, ltcmelo wrote:
Quote:
On Sep 29, 2:54 am, Erik Wikström <Erik-wikst...@telia.comwrote:
Quote:
>On 2007-09-29 11:51, zou wrote:
>>
Quote:
there is a file which is very large,
>>
Quote:
we can use stat to get a file size(<2G),
struct stat buf;
stat("file", &buf);
long s=(long)stat.st_size;
>>
Quote:
but stat::st_size is type of off_t(typedef long),
so how about a file larger than 2G?
>>
>stat() is POSIX, not C++ so you are off topic. Further more the only
>requirement I could find on off_t was that it should be a signed
>integral type, so it might just as well be a long long or an int. The
>type of off_t is platform dependent, so if your platform uses a 32 bit
>long and off_t is a long then you can not work with files larger than 2
>GiB. For more information contact your platform vendor.
>
Hi.
>
If you're working with gcc, you might want to take a look at
http://www.delorie.com/gnu/docs/glibc/libc_285.html. There's a
compiler flag (_FILE_OFFSET_BITS) which allows you to work with
functions like lstat64, fstat64, and others, in 32-bit environment.
Please do not quote signatures.

Actually the link you posted have nothing to do with gcc, but rather the
GNU C library implementation, and while it is probably shipped with gcc
many platforms uses their own (like the BSD systems, and probably
Solaris too). Of course all of those have the ability to work with files
larger than 2 GiB, but those ways are platform specific and the OP
should ask in a group discussing the system for more information.

--
Erik Wikström
Closed Thread