[GH-ISSUE #157] Error creating tmpfile(s) on WindowsXP #128

Closed
opened 2026-05-05 11:44:25 -06:00 by gitea-mirror · 7 comments
Owner

Originally created by @goyzhang on GitHub (Mar 19, 2018).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/157

Originally assigned to: @jmcnamara on GitHub.

I'm working on a project which has to be on Windows XP SP3 platform. I tested my codes on Windows 7 and 10. They all work fine. However,on the XP side, I keep getting this error message when workbook_close() is called. After that an empty xlsx file will be created for output.
20180319161026
It seems like the program is somehow unable to create a temp file. Is there any workaround?

Originally created by @goyzhang on GitHub (Mar 19, 2018). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/157 Originally assigned to: @jmcnamara on GitHub. I'm working on a project which has to be on Windows XP SP3 platform. I tested my codes on Windows 7 and 10. They all work fine. However,on the XP side, I keep getting this error message when _workbook_close()_ is called. After that an empty xlsx file will be created for output. ![20180319161026](https://user-images.githubusercontent.com/24909320/37584489-ab38cd62-2b90-11e8-9635-130d18d29697.png) It seems like the program is somehow unable to create a temp file. Is there any workaround?
gitea-mirror 2026-05-05 11:44:25 -06:00
Author
Owner

@jmcnamara commented on GitHub (Mar 19, 2018):

Hi,

Libxlsxwriter uses a library called tmpfileplus to ensure that the library can create the temporary files it needs to create an xlsx file.

The code for that is in the libxslxwriter repo: https://github.com/jmcnamara/libxlsxwriter/blob/master/third_party/tmpfileplus/tmpfileplus.c

In particular this part is important:

#ifdef _WIN32
	tempdirs[i++] = getenv_save("TMP", env1, sizeof(env1));
	tempdirs[i++] = getenv_save("TEMP", env2, sizeof(env2));
#else
	tempdirs[i++] = getenv_save("TMPDIR", env3, sizeof(env3));
	tempdirs[i++] = P_tmpdir;
#endif

Are those directories/environmental variables (TMP or TEMP) accessible to your application? Or was the application compiled without _WIN32 so that it is trying to use TMPDIR which doesn't exist on Win XP?

Either way you can directly control the tempdir location from your application, if required, as follows: Specifying a TEMP directory for libxlsxwriter.

John

<!-- gh-comment-id:374166566 --> @jmcnamara commented on GitHub (Mar 19, 2018): Hi, Libxlsxwriter uses a library called [tmpfileplus](https://www.di-mgt.com.au/c_function_to_create_temp_file.html) to ensure that the library can create the temporary files it needs to create an xlsx file. The code for that is in the libxslxwriter repo: https://github.com/jmcnamara/libxlsxwriter/blob/master/third_party/tmpfileplus/tmpfileplus.c In particular this part is important: ```C #ifdef _WIN32 tempdirs[i++] = getenv_save("TMP", env1, sizeof(env1)); tempdirs[i++] = getenv_save("TEMP", env2, sizeof(env2)); #else tempdirs[i++] = getenv_save("TMPDIR", env3, sizeof(env3)); tempdirs[i++] = P_tmpdir; #endif ``` Are those directories/environmental variables (`TMP` or `TEMP`) accessible to your application? Or was the application compiled without `_WIN32` so that it is trying to use `TMPDIR` which doesn't exist on Win XP? Either way you can directly control the tempdir location from your application, if required, as follows: [Specifying a TEMP directory for libxlsxwriter](http://libxlsxwriter.github.io/getting_started.html#gsg_tmpdir). John
Author
Owner

@goyzhang commented on GitHub (Mar 20, 2018):

Thank you. The directory refer to c:\docume~1\admini~1\locals~1\temp in WinXP. The directory exists and I was in Administrator. I did compile in WIN32.
lxw_workbook_options fails to work.
lxw_workbook_options options = { LXW_FALSE,(char*)"C:\\Temp" };
In WinXP, I tried C:\Temp but no luck. The project is a VS2017 dll. Maybe I should take a deeper look at what was really going on.

<!-- gh-comment-id:374500505 --> @goyzhang commented on GitHub (Mar 20, 2018): Thank you. The directory refer to `c:\docume~1\admini~1\locals~1\temp` in WinXP. The directory exists and I was in Administrator. I did compile in WIN32. `lxw_workbook_options` fails to work. `lxw_workbook_options options = { LXW_FALSE,(char*)"C:\\Temp" };` In WinXP, I tried C:\\Temp but no luck. The project is a VS2017 dll. Maybe I should take a deeper look at what was really going on.
Author
Owner

@goyzhang commented on GitHub (Mar 20, 2018):

@jmcnamara Hi John,
After some trial-and-error by turning SHOW_DPRINTF on, I found out that in static FILE *mktempfile_internal(const char *tmpdir, const char *pfx, char **tmpname_ptr, int keep) the function is_valid_dir is returning the wrong value under WinXP(it should return 1). After forcing it to return 1,everything works fine. I'm a starter on C programing, any idea how is that happen and how to fix it? Thank you.

<!-- gh-comment-id:374512997 --> @goyzhang commented on GitHub (Mar 20, 2018): @jmcnamara Hi John, After some trial-and-error by turning SHOW_DPRINTF on, I found out that in `static FILE *mktempfile_internal(const char *tmpdir, const char *pfx, char **tmpname_ptr, int keep)` the function `is_valid_dir` is returning the wrong value under WinXP(it should return 1). After forcing it to return 1,everything works fine. I'm a starter on C programing, any idea how is that happen and how to fix it? Thank you.
Author
Owner

@jmcnamara commented on GitHub (Mar 20, 2018):

the function is_valid_dir is returning the wrong value under WinXP(it should return 1).

What value did it return?

Also, what compiler are you using?

<!-- gh-comment-id:374521714 --> @jmcnamara commented on GitHub (Mar 20, 2018): > the function is_valid_dir is returning the wrong value under WinXP(it should return 1). What value did it return? Also, what compiler are you using?
Author
Owner

@goyzhang commented on GitHub (Mar 20, 2018):

It returns 0 as (stat(path, &st) == 0) is False. I use Visual Studio 2015 - Windows XP (v140_xp) platform toolset. So I think it's MSBuild by default?

<!-- gh-comment-id:374523598 --> @goyzhang commented on GitHub (Mar 20, 2018): It returns 0 as `(stat(path, &st) == 0)` is False. I use **Visual Studio 2015 - Windows XP (v140_xp)** platform toolset. So I think it's MSBuild by default?
Author
Owner

@goyzhang commented on GitHub (Mar 21, 2018):

@jmcnamara Problem solved by changing the code generation runtime library from /MT to /MD. Not sure if the dynamic linking would bring any side effect.

<!-- gh-comment-id:374834546 --> @goyzhang commented on GitHub (Mar 21, 2018): @jmcnamara Problem solved by changing the code generation runtime library from **/MT** to **/MD**. Not sure if the dynamic linking would bring any side effect.
Author
Owner

@ghost commented on GitHub (May 3, 2018):

In our case, we could not use /MD. The problem seems to be with tmpfileplus. Works well when building with define USE_STANDARD_TMPFILE.

<!-- gh-comment-id:386261030 --> @ghost commented on GitHub (May 3, 2018): In our case, we could not use /MD. The problem seems to be with tmpfileplus. Works well when building with define USE_STANDARD_TMPFILE.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#128
No description provided.