2

I am trying to open a tga file on Mac OS X, I have spent past hour fiddeling with this issue, with no luck. I simply want to open a tga file. Here is what I have tried so far,

    int filedesc = open("/Users/x2am/Desktop/1177.tga", O_RDONLY);
    if(filedesc < 0)
            printf("%s ",strerror(errno));

output> Operation not permitted

    FILE* fp = fopen("/Users/x2am/Desktop/1177.tga", "rb");
    if(fp == NULL) printf("file not loaded");

output> file not loaded

   filename = L"/Users/x2am/Desktop/1177.tga";
   std::string narrow(filename.begin(), filename.end());
   fstream file(narrow.c_str(), ios::in | ios::binary);
   if (!file.good()) printf("file not loaded");

output> file not loaded

Considering the output from open(), somehow the operation wasn't permitted.

Here is the get info i performed on the image.

enter image description here

The app is sandboxed, enter image description here

Now I guess I have tried everything I could. Is there something invisible in front of me that I am missing? Any help much appreciated :)

Undo
  • 25,519
  • 37
  • 106
  • 129
2am
  • 378
  • 1
  • 6
  • 18
  • Is the application sandboxed? – Chris Devereux Feb 19 '14 at 13:37
  • Yes. it is sandboxed. I will update the question with the file access list from sandboxing page in build settings. – 2am Feb 19 '14 at 13:39
  • IIRC, sandboxed applications can only access files that the user has explicitly permitted through the file dialog. – molbdnilo Feb 19 '14 at 14:02
  • 2
    you can put the file in the container directory, or open it by finder once and save the access privilege. read here: https://developer.apple.com/library/mac/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html#//apple_ref/doc/uid/TP40011183-CH3-SW4 – SHR Feb 19 '14 at 14:09
  • @molbdnilo, the tga file that I am trying to open is downloaded from ftp server at runtime. So, is there anyway apart from disabling the sandboxing I can open the file? – 2am Feb 19 '14 at 14:10
  • @SHR, sounds like a plan. :) thanks i will try that. – 2am Feb 19 '14 at 14:11

1 Answers1

5

The issue was indeed because of the apple sandboxing. This again rises the question, apple sandbox: friend or enemy? After putting the file in /Users/USER/Library/Container/com.xxx.xxx/Data/ it worked. Much thanks to @SHR, for the ans :)

2am
  • 378
  • 1
  • 6
  • 18
  • Another option, e.g. if you're building an app that's not for distribution, is to turn off sandboxing for your app: https://stackoverflow.com/questions/7018354/remove-sandboxing – Jon Schneider Mar 16 '21 at 14:57