How do I use mkstemp(3) to create a temp directory?

I ran into literature that suggests creating a temporary directory using mkstemp(3). I think the idea is to create a random path that is unlikely to be duplicated. The documentation on mkstemp is unclear to me. How do you use it to create a temp directory in iOS? mkstemp takes an unsafe mutable pointer as an argument and returns and Int32. I have no idea what to do with those in the context of file system management.


Any help on this will be appreciated.

Accepted Reply

I do not recommend you to use such low level functions in iOS programming.


The file system of iOS is sandboxed and your app has its own temporary directory, so it's very rare you need to care about uniqueness.

And in sandboxed environment some low level functions would not work as expected.

As you see using low level C functions are difficult to use, especially when you use Swift.


Why do you want to create a randome path that is unlikely to be duplicated ?

If you can describe the reason why you want to do it, there may be a better way matching iOS.

Replies

I do not recommend you to use such low level functions in iOS programming.


The file system of iOS is sandboxed and your app has its own temporary directory, so it's very rare you need to care about uniqueness.

And in sandboxed environment some low level functions would not work as expected.

As you see using low level C functions are difficult to use, especially when you use Swift.


Why do you want to create a randome path that is unlikely to be duplicated ?

If you can describe the reason why you want to do it, there may be a better way matching iOS.

I'm just following ideas I get from the programming community. I see your point. I could just use the designated temp directory.