Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

My cocoa application uses one library written in 'C' which is tryings write file at '/tmp' path. This creates sandbox violations. In Cocoa we can use 'NSTemporaryDirectory' API. To fix sandbox violation Is it safe to use 'tmpfile' API in sandboxed environment? Are there in any other solutions?

share|improve this question
    
Do you want a C API or does Obj-C API work for you as suggested in your question: In Cocoa we can use 'NSTemporaryDirectory' API? –  Mar0ux May 30 '13 at 7:10
    
I want use C API. –  Devara Gudda May 30 '13 at 7:14
    
Thanks for clarifying, I have removed my answer. –  Mar0ux May 30 '13 at 7:19

1 Answer 1

EDITED After actually testing it

No, tmpnam() won't work and I think the only way to get a temporary filename is to provide a .m file with your library specifically for use with iOS and OSX, which can be used return the temporary directory as a C-String:

apple.h:

#pragma once

extern size_t getTemporaryDirectory(char *buffer, size_t len);

apple.m:

size_t getTemporaryDirectory(char *buffer, size_t len)
{
    @autoreleasepool
    {
        NSString *tempDir = NSTemporaryDirectory();
        if (tempDir != nil)
        {
            const char *utf = [tempDir UTF8String];
            strncpy(buffer, utf, len);
            return strlen(utf);
        }
    }
    return 0;
}
share|improve this answer
    
To me this is not working. I am getting following log in Console.<AppName>(10920) deny file-write-create /private/var/tmp/tmp.0.7SUvca. I am using following code to test in Sandboxed test application. char *tmpFname = tmpnam(NULL); NSLog(@"Temp File name : %s",tmpFname); [@"Test" writeToFile:[NSString stringWithUTF8String:tmpFname] atomically:NO encoding:NSUTF8StringEncoding error:NULL]; –  Devara Gudda May 30 '13 at 12:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.