Re: Temporary files best practice?
Re: Temporary files best practice?
- Subject: Re: Temporary files best practice?
- From: "Finlay Dobbie" <email@hidden>
- Date: Sun, 2 Sep 2007 19:42:10 +0100
On 02/09/07, Andrew Merenbach <email@hidden> wrote:
> What about creating temporary folder subfolders, though? Looking at
> the mkstemp man page, it doesn't sound as though mkstemp supports
> making folders. If one wishes to write property-list-style data, the
> file descriptor from mkstemp() would be inadequate unless on wishes
> to convert to NSData, right?
Not exactly hard, though, is it? You could try something like this
(typed in Mail, no error handling, only for illustration purposes):
NSString *errorString = nil;
NSData *plistData = [NSPropertyListSerialization
dataFromPropertyList:aPlist format:NSPropertyListBinaryFormat_v1_0
errorDescription:&errorString];
char *tmpNam = strcpy("/tmp/com.my.app.XXX.plist");
int fd = mkstemps(tmpNam, 6);
NSFileHandle *fh = [[NSFileHandle alloc] initWithFileDescriptor:fd
closeOnDealloc:YES];
[fd writeData:plistData];
[fd release];
free(tmpName);
You could either keep the fd around or hold on to tmpNam if you want
to reference the file later.
-- Finlay
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden