64 bits : off_t , off64_t

hi,
the file that i am trying to write is going to be about 12GBs.

I browse the net and found that it is not advisable to use unsigned int but use off64_t or off_t but when i put it , i get error error: ‘off64_t’ was not declared in this scope

is there a specific header file i need to put? thanks...
zizi21Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
evilrixConnect With a Mentor Senior Software Engineer (Avast)Commented:
Just use off_t and when you enable LFS this will automatically become a 64 bit type.

"Compile your programs with "gcc -D_FILE_OFFSET_BITS=64". This forces all file access calls to use the 64 bit variants. Several types change also, e.g. off_t becomes off64_t. It's therefore important to always use the correct types and to not use e.g. int instead of off_t. "
0
 
Infinity08Commented:
What OS are you using ? Is it a 64bit or 32bit OS ?
0
 
zizi21Author Commented:
i need it to work on 32 bit and 64 bit machine..

for testing purpose, i am using mac, but i need to run on both (32 bit and 64 bit) . thanks.
0
Become a Leader in Data Analytics

Gain the power to turn raw data into better business decisions and outcomes in your industry. Transform your career future by earning your MS in Data Analytics. WGU’s MSDA program curriculum features IT certifications from Oracle and SAS.  

 
evilrixSenior Software Engineer (Avast)Commented:
Hi zizi21.

IIRC your questions are generally Linux related. If this is the case here and you are using gcc you can enable large file support in the standard C library by defining _FILE_OFFSET_BITS=64 during the build phase of your project.

The following link contains more info.
http://www.suse.de/~aj/linux_lfs.html
0
 
evilrixSenior Software Engineer (Avast)Commented:
>> for testing purpose, i am using mac
I suspect the LFS info will be applicable to a max too if you are using OS-X
0
 
zizi21Author Commented:
evilrix,

thanks for the reply.

my problem is that i am saving the pointer of the file in the code as well and that is of type unsigned int. since unsigned int canbe as big as 12 GB, i need to use something bigger...
0
 
zizi21Author Commented:
" It's therefore important to always use the correct types and to not use e.g. int instead of off_t"

could i clarify this...i am using unsigned int when i get value from ftell, store positions in file using unsigned int,,,is that wrong ? the reason i used unsigned int was because it could store more instead of ints...
0
 
evilrixSenior Software Engineer (Avast)Commented:
>> ,is that wrong
Yes

>>  the reason i used unsigned int was because it could store more instead of ints...
int us a signed value and unsigned int is an unsigned value. The different is that int can store positive and negative values whereas unsigned in can only store positive values. Neither are the correct type to use when dealing with large files as neither are guaranteed to be 64 bit, even on a 64 bit platform.

The type off_t IS guaranteed to be 64 bit when LFS is enabled.
0
 
zizi21Author Commented:
thanks a million.. i would start changing the types to off_t type now...thanks again..
0
 
zizi21Author Commented:
thanks and God bless you.
0
 
evilrixSenior Software Engineer (Avast)Commented:
>> thanks a million
No worries... if you need more info just post back here.
0
 
zizi21Author Commented:
thanks
0
All Courses

From novice to tech pro — start learning today.