[chuck-dev] chuck --shell writes to root directory under Windows

Steve Nicholson lists at steveandmimi.com
Tue Nov 26 19:13:52 EST 2013


When investigating the issue I reported earlier today, my classmates and I discovered that under Windows chuck --shell writes its temporary file to c:\. This will most likely fail if the user doesn't have admin rights. This is apparently because the tmpnam function under Windows only returns a file name whereas under OS X it returns a file name that includes a complete path to the system's temporary directory.

I used the information from this article (http://msdn.microsoft.com/en-us/library/windows/desktop/aa363875(v=vs.85).aspx) to create a temporary file name that includes a path to an appropriate directory. Here is the diff for chuck_shell.cpp:

606a607,623
> #if defined __PLATFORM_WIN32__
> 	char * tmp_filepath = NULL;
> 	TCHAR tempFileName[MAX_PATH];
> 	TCHAR tempPathBuffer[MAX_PATH];
> 	DWORD dwRetVal = 0;
> 	UINT uRetVal = 0;
> 	dwRetVal = GetTempPath(MAX_PATH, tempPathBuffer);
> 	if (dwRetVal > 0 && dwRetVal < MAX_PATH)
> 	{
> 		uRetVal = GetTempFileName(tempPathBuffer, TEXT("ChucK"), 0, tempFileName);
> 		if (uRetVal != 0)
> 		{
> 			//Successfully created temp file name. Point tmp_filepath at it.
> 			tmp_filepath = tempFileName;
> 		}
> 	}
> #else
607a625,626
> #endif
> 


-Steve


More information about the chuck-dev mailing list