7537 – `File.tmpfile` requires administrator rights on Windows

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7537 - `File.tmpfile` requires administrator rights on Windows
Summary: `File.tmpfile` requires administrator rights on Windows
Status: REOPENED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Windows
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
Reported: 2012年02月18日 00:42 UTC by Denis Shelomovskii
Modified: 2024年12月01日 16:14 UTC (History)
4 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Denis Shelomovskii 2012年02月18日 00:42:44 UTC
---
import std.stdio;
void main() {
 File.tmpfile();
}
---
dmd 2.058 compiled version running from non-administrator fails with: std.exception.ErrnoException Could not create temporary file with tmpfile() (Permission denied) at std\stdio.d(875)
Comment 1 Vladimir Panteleev 2012年04月05日 19:23:30 UTC
File.tmpfile is just a simple wrapper around core.stdc.stdio.tmpfile, so the issue is with the DMC's C standard library.
Comment 2 SomeDude 2012年04月19日 09:01:44 UTC
This is not a bug. It works as intended. Should close.
Comment 3 Vladimir Panteleev 2012年04月19日 09:03:04 UTC
What?? How is this not a bug?
Comment 4 SomeDude 2012年04月19日 09:09:13 UTC
(In reply to comment #3)
> What?? How is this not a bug?
The OS prevents to create the file, so tmpfile() throws an exception. I don't see how this can be considered a bug.
Comment 5 Vladimir Panteleev 2012年04月19日 09:10:28 UTC
The filename is chosen by the C runtime, not the operating system. It is a bug in the DigitalMars C runtime. It probably tries to use the hard-coded %WINDIR%\Temp directory, instead of the user profile directory or %TEMP%.
Comment 6 SomeDude 2012年04月19日 09:19:52 UTC
Oh, I just saw the author of the issue. It's not "random Denis".
Anyway, has a bug report been done in DMC C bugzilla ?
Else this one will stay open forever, I'm affraid.
Comment 7 Walter Bright 2012年04月19日 11:23:55 UTC
(In reply to comment #5)
> The filename is chosen by the C runtime, not the operating system. It is a bug
> in the DigitalMars C runtime. It probably tries to use the hard-coded
> %WINDIR%\Temp directory, instead of the user profile directory or %TEMP%.
Actually, it uses stdio.h's _P_tmpdir, which on Windows is "\\". Did I say that implementation is rather old? I also noticed that Windows 7 does not allow writing to the root directory. XP allowed it.
Comment 8 Vladimir Panteleev 2012年04月19日 11:32:02 UTC
(In reply to comment #7)
> XP allowed it.
You mean, to administrator users? I don't think regular users can create files in the drive root on XP either:
http://dump.thecybershadow.net/2d089ee536e35b4a8244f26f36be491c/00000814.png 
Comment 9 Walter Bright 2012年04月19日 12:15:09 UTC
I have it fixed in snn.lib now. You can pick it up here:
ftp://ftp.digitalmars.com/dmc.zip 
Comment 10 Vladimir Panteleev 2014年01月28日 01:52:42 UTC
(In reply to comment #3)
> What?? How is this not a bug?
I may have been wrong here. The problem is not present on Win32, but on Win64 the MS runtime does what the DMC runtime used to do - attempt to create the file in the drive root. And it's not a bug, it's working according to the documentation:
> The tmpfile function creates a temporary file and returns a pointer to that 
> stream. The temporary file is created in the root directory. To create a 
> temporary file in a directory other than the root, use tmpnam or tempnam in 
> conjunction with fopen.
Conclusion: this function is horrible and needs to be replaced with something better.
Some relevant discussion here:
https://github.com/D-Programming-Language/phobos/pull/691 
Comment 11 berni44 2019年12月12日 16:58:52 UTC
Is this still not fixed?
Comment 12 dlangBugzillaToGithub 2024年12月01日 16:14:55 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB
https://github.com/dlang/phobos/issues/9923
DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB


AltStyle によって変換されたページ (->オリジナル) /