• C

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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Introducing the "443 Security Simplified" Podcast

This new podcast puts you inside the minds of leading white-hat hackers and security researchers. Hosts Marc Laliberte and Corey Nachreiner turn complex security concepts into easily understood and actionable insights on the latest cyber security headlines and trends.

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
evilrixSenior 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.