• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Temporary files best practice?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

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>)

  • Prev by Date: Re: Temporary files best practice?
  • Next by Date: Re: Why no -[NSManagedObjectContext deleteObjects:] ?
  • Previous by thread: Re: Temporary files best practice?
  • Next by thread: my preferences sheet appears under XCode not under the app ...
  • Index(es):
    • Date
    • Thread