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

Discussion in 'Mac Programming' started by sunilkumarg, May 8, 2012.

  1. sunilkumarg, May 8, 2012
    Last edited by a moderator: May 8, 2012

    macrumors newbie

    Joined:
    Apr 11, 2012
    #1
    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
     
  2. subsonix, May 8, 2012
    Last edited by a moderator: May 8, 2012

    macrumors 68040

    Joined:
    Feb 2, 2008
    #2
    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.
     
  3. gnasher729, May 8, 2012
    Last edited by a moderator: May 8, 2012

    macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #3
    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.
     
  4. laprej, May 8, 2012
    Last edited: May 8, 2012

    macrumors regular

    Joined:
    Oct 14, 2005
    Location:
    Troy, NY
    #4
    A few possibilities come to mind:
    1. 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"
    2. 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.
     
  5. thread starter macrumors newbie

    Joined:
    Apr 11, 2012
    #5
    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
     
  6. subsonix, May 9, 2012
    Last edited: May 9, 2012

    macrumors 68040

    Joined:
    Feb 2, 2008
    #6
    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.
     
  7. thread starter macrumors newbie

    Joined:
    Apr 11, 2012
    #7
    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;
    }
     
  8. macrumors 68040

    Joined:
    Feb 2, 2008
    #8
    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.

    Code:
    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)
     
  9. gnasher729, May 9, 2012
    Last edited: May 9, 2012

    macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #9
    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.
     
  10. thread starter macrumors newbie

    Joined:
    Apr 11, 2012
    #10
    Hey what u mean ???What u r trying say :)
     
  11. thread starter macrumors newbie

    Joined:
    Apr 11, 2012
    #11
    Iam able to open large file and able to compare files

    Thanks guys
     
  12. macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle

Share This Page