Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
June 23, 2018, 07:04:17 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
   Home   Help Search Login Register Chat  
Pages: [1]   Go Down
Author Topic: Question: Ex 5 (unique tmp file name)  (Read 2066 times)
Global Moderator
Full Member
Posts: 230

« on: February 07, 2009, 12:06:45 AM »

I used 2 ways to generate unique file names -- first by the Foundation methods as specified in exercise 5 and then by the C library function mkstemp(char *).

I usually get a really long (unique) file name by the Foundation methods like below.

Unique file name by Foundation methods =

Unique file name by mkstemp = /tmp/temp.HbY7zES4

The file name generated by mkstemp is shorter and I also have some control over its length.

So if both ways offer unique (temporary) file names, which is preferred for iphone/Mac apps?


Hero Member
Posts: 3114

« Reply #1 on: February 10, 2009, 11:53:45 AM »

In general I would use a framework method over a corresponding C or Unix system routine unless there are specific issues related to performance or security that you need to address.  The framework method will  be designed to work within the framework's memory allocation scheme, and I would be more confident in a CocoaTouch method (for example) being well-behaved within the application than even a corresponding C library routine or perhaps Unix system call.

In the case of  NSTemporaryDirectory, I know the temporary directory got moved between OS X releases to a place that would be considered more secure (files created in /tmp are  potentially exposed to other users on the system). 

The length of the file name that gets generated should be a nonissue since you shouldn't need to use that name explicitly in your code.
Posts: 9

« Reply #2 on: February 18, 2009, 09:28:41 PM »

In general I personally even tempt to create rather a random directory below the default temp dir and clean this directory up at the end of my application, delete it inclusive all files in it to make sure I leave no garbage behind at all.
There I can then even use descriptive filenames , new directories or whatever I like for myself as I do not have to think if someone else created there a file with that name before me ever.
Hero Member
Posts: 3114

« Reply #3 on: February 19, 2009, 11:32:40 AM »

In general, you have to be careful when creating files in "standard" temporary directories to make sure another program is not monitoring that directory and can then potentially gain access to the file.  It's a well-known security risk that you have to be careful about with respect to file permissions:  If someone has permission to link to a file created in a temporary directory, that file will persist even after the application deletes the file.


Pages: [1]   Go Up
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents ゥ 2009 All rights reserved.