spencersalazar / chuck

28 stars 8 forks source link

win32 Temp files written to root of C: drive #22

Closed SSteve closed 10 years ago

SSteve commented 10 years ago

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 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
> 
spencersalazar commented 10 years ago

Thanks SSteve. As a said in a different post we don't use chuck --shell that much here, so it hasnt received many updates for fixing bugs such as this. This issue looks pretty cut and dry, so I think we can integrate the fix for the next release.

SSteve commented 10 years ago

Given your comment in #21 about using forward slashes in Windows file names, do you think it would be a good idea to convert the backslashes in this file name to forward slashes? That would automatically fix #21 without any changes to the code. (Assuming Windows is happy with the forward slashes.)

spencersalazar commented 10 years ago

Hi,

This has been fixed as of dce7872ef5af7787da803bcd376f121076c34067 and will be folded into an upcoming release. Feel free to compile + try it out in advance of that!

Thanks, spencer