we need to change the default SYSTEM temp folder for our multiplatform application.
The systems default call for getting the SYSTEM temp folder should return the folder we have specified. On MS-Windows this is GetTempPath(). On MacOS the function is called NSTemporaryDirectory() I think.
We need to do this because we are running multiple instances of our application at the same time. There are some 3rd party libs which are using non-unique temporary filenames stored in the SYSTEMs temp folder.
For Microsoft Windows and for Unix platforms we already have a solution:
Microsoft Windows:
setenv("TMP", myOwnTempFolder);
tmpFolderToUse=GetTempPath(); // use WinOS API call
Unix:
setenv("TMPDIR", myOwnTempFolder);
tmpFolderToUse = getenv("TMPDIR");
but this doesn't work for MacOS(X).
MacOS:
setenv("TMPDIR", myOwnTempFolder);
tmpFolderToUse = NSTemporaryDirectory(); // use MacOS API call
The call to NSTemporaryDirectory() always returns the default path afterwards (as without setting a different folder).
I have tried to invoke setenv("...") with TMPDIR, TEMP, TEMPDIR, and TMP - but no luck on MacOSX.
For clarification: here a multiple instance pseudo-code example as it currently implemented for the Windows OS flavor of our application:
instance1:
tmp=GetTempPath(); // -> 'C:\User\testing\temp'
uuid=getUUID(); // -> 'd7c5df40-d48d-11de-8a39-0800200c9a66'
setenv("TMP", tmp + uuid);
tmp=GetTempPath(); // --> 'C:\User\testing\temp\d7c5df40-d48d-11de-8a39-0800200c9a66'
instance2:
tmp=GetTempPath(); // -> 'C:\User\testing\temp'
uuid=getUUID(); // -> '435aeb10-d48e-11de-8a39-0800200c9a66'
setenv("TMP", tmp + uuid);
tmp=GetTempPath(); // --> 'C:\User\testing\temp\435aeb10-d48e-11de-8a39-0800200c9a66'
Any advice on how to achieve the same behavior on MacOS would be very apricated.