Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Temporary files best practice?



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >Temporary files best practice? (From: Knut Lorenzen <email@hidden>)
 >Re: Temporary files best practice? (From: Andrew Merenbach <email@hidden>)
 >Re: Temporary files best practice? (From: Wincent Colaiuta <email@hidden>)
 >Re: Temporary files best practice? (From: Andrew Merenbach <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.