PDA

View Full Version : can't open large file (>4GB) on MAC using standard C API's (fopen)




sunilkumarg
May 8, 2012, 08:53 AM
Hi I have 64bit application which compare two files.This application support upto 2 GB FILE only , But i want support large file (20 GB File).
But Iam getting Error "file cant open"while using application
Running application on 64bit MAC machine.
I think so.In 64 bit machine We can support upto 2^64 size.

Plase help me

Thanks in advance
Sunny



subsonix
May 8, 2012, 10:43 AM
You should be able to open the file regardless of size, reading it all into memory is another issue though. Can you post the code where you are opening the file.

gnasher729
May 8, 2012, 11:49 AM
Hi I have 64bit application which compare two files.This application support upto 2 GB FILE only , But i want support large file (20 GB File).
But Iam getting Error "file cant open"while using application
Running application on 64bit MAC machine.
I think so.In 64 bit machine We can support upto 2^64 size.

Plase help me

Thanks in advance
Sunny

You've given us a lot of useful information to diagnose the problem. :mad: So I'd say the answer is that you made a mistake somewhere and you need to read the documentation.

Alternatively, try to think about what we might need to actually help you.

laprej
May 8, 2012, 07:40 PM
A few possibilities come to mind:

Your application is not actually compiled 64-bit. You can check this in the terminal using the "file" command, e.g. "file a.out" If this is the case, you can recompile it and pass -m64, e.g. "gcc -m64 foo.c"
If you're using the fopen() call, it should set errno. You can use perror() and friends to check that. Look at the perror man page.

sunilkumarg
May 9, 2012, 12:57 AM
You've given us a lot of useful information to diagnose the problem. :mad: So I'd say the answer is that you made a mistake somewhere and you need to read the documentation.

Alternatively, try to think about what we might need to actually help you.

Hi,

We have API's in windows
_ftelli64() ;
_fseeki64();
on Linux
lseek64();
ltell64();

For doing 64 bit file opeartion like this do we have any API's on MAC for doing 64 bit file operation.

Best and regards
Sunny

subsonix
May 9, 2012, 03:45 AM
Hi,

We have API's in windows
_ftelli64() ;
_fseeki64();
on Linux
lseek64();
ltell64();

For doing 64 bit file opeartion like this do we have any API's on MAC for doing 64 bit file operation.

Best and regards
Sunny

Look at the fseek, ftell man pages, pick the version with off_t arguments (The fseeko() and ftello() functions conform to IEEE Std 1003.1-2001 (``POSIX.1'')). OS X conforms to posix and unix03 unlike Linux. This still has nothing to do with your problem of opening the file..

Still, you can use fseek and ftell since a long on LP64 systems (all unixes, not windows) are 8 bytes. It's signed so you maximum file size has to be below 2^63, i.e waaaayy beyond your needs.

sunilkumarg
May 9, 2012, 04:07 AM
Look at the fseek, ftell man pages, pick the version with off_t arguments (The fseeko() and ftello() functions conform to IEEE Std 1003.1-2001 (``POSIX.1'')). OS X conforms to posix and unix03 unlike Linux. This still has nothing to do with your problem of opening the file..

Still, you can use fseek and ftell since a long on LP64 systems (all unixes, not windows) are 8 bytes. It's signed so you maximum file size has to be below 2^63, i.e waaaayy beyond your needs.

Thanks for support

iam able to open smaller size file but large file iam not able to open

check this code small code

fp1 = fopen(argv[1],"rb");
fp2 = fopen(argv[2],"rb");


if ((fp1 == NULL) && (fp1 == NULL))
{
printf("File can't be opened : %s\n", argv[2]);
printf("File can't be opened : %s\n", argv[1]);
fprintf(outfp,"%s,%s,%s\n",argv[1],argv[2],"NO FILES TO COMPARE");
abort_flag= 1;
}

subsonix
May 9, 2012, 04:23 AM
Thanks for support

iam able to open smaller size file but large file iam not able to open

check this code small code

fp1 = fopen(argv[1],"rb");
fp2 = fopen(argv[2],"rb");


if ((fp1 == NULL) && (fp1 == NULL))
{
printf("File can't be opened : %s\n", argv[2]);
printf("File can't be opened : %s\n", argv[1]);
fprintf(outfp,"%s,%s,%s\n",argv[1],argv[2],"NO FILES TO COMPARE");
abort_flag= 1;
}

If you are not able to open larger files it's coincidental, you should take the advice from above and use perror, which will tell you the reason why you could not open the files.


if( (fp = fopen(argv[1], "rb")) == NULL ) {
perror(argv[1]);
return errno;
}

if( (fp2 = fopen(argv[2], "rb")) == NULL ) {
perror(argv[2]);
return errno;
}


(include errno.h btw)

gnasher729
May 9, 2012, 05:14 AM
For doing 64 bit file opeartion like this do we have any API's on MAC for doing 64 bit file operation.


MAC is the abbreviation for "Media Access Control". Every Mac has a MAC address which uniquely identifies the computer, so does just about every PC. What you are talking about is a Mac.

And the answer is "Yes". When you go into terminal and enter "man ftell", what functions other than ftell does it mention? So which one are you going to use? What parameter types do these functions have? Which ones will work with huge files on a 64 bit system, and which ones will work both on 32 bit and 64 bit systems?

This is just exhausting. Does nobody teach you guys how to use a computer to actually find out things? Do you have no curiosity at all to learn things on your own? I could tell you which one to use, but this is just too stupid.

BTW. I recommend turning on the spelling checker in Safari.

sunilkumarg
May 9, 2012, 06:17 AM
MAC is the abbreviation for "Media Access Control". Every Mac has a MAC address which uniquely identifies the computer, so does just about every PC. What you are talking about is a Mac.

And the answer is "Yes". When you go into terminal and enter "man ftell", what functions other than ftell does it mention? So which one are you going to use? What parameter types do these functions have? Which ones will work with huge files on a 64 bit system, and which ones will work both on 32 bit and 64 bit systems?

This is just exhausting. Does nobody teach you guys how to use a computer to actually find out things? Do you have no curiosity at all to learn things on your own? I could tell you which one to use, but this is just too stupid.

BTW. I recommend turning on the spelling checker in Safari.

Hey what u mean ???What u r trying say :-)

sunilkumarg
May 9, 2012, 07:30 AM
If you are not able to open larger files it's coincidental, you should take the advice from above and use perror, which will tell you the reason why you could not open the files.


if( (fp = fopen(argv[1], "rb")) == NULL ) {
perror(argv[1]);
return errno;
}

if( (fp2 = fopen(argv[2], "rb")) == NULL ) {
perror(argv[2]);
return errno;
}


(include errno.h btw)
Iam able to open large file and able to compare files

Thanks guys

jared_kipe
May 9, 2012, 10:06 AM
Did you '#include <stdio.h>'?