Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File.tmpfile requires administrator rights on Windows #9923

Open
dlangBugzillaToGithub opened this issue Feb 18, 2012 · 11 comments
Open

File.tmpfile requires administrator rights on Windows #9923

dlangBugzillaToGithub opened this issue Feb 18, 2012 · 11 comments
Labels
Arch:x86_64 Issues specific to x86_64 OS:Windows Issues Specific to Windows Severity:Normal

Comments

@dlangBugzillaToGithub
Copy link

verylonglogin.reg (@denis-sh) reported this on 2012-02-18T00:42:44Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=7537

CC List

Description

---
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)
@dlangBugzillaToGithub
Copy link
Author

dlang-bugzilla (@CyberShadow) commented on 2012-04-05T19:23:30Z

File.tmpfile is just a simple wrapper around core.stdc.stdio.tmpfile, so the issue is with the DMC's C standard library.

@dlangBugzillaToGithub
Copy link
Author

lovelydear commented on 2012-04-19T09:01:44Z

This is not a bug. It works as intended. Should close.

@dlangBugzillaToGithub
Copy link
Author

dlang-bugzilla (@CyberShadow) commented on 2012-04-19T09:03:04Z

What?? How is this not a bug?

@dlangBugzillaToGithub
Copy link
Author

lovelydear commented on 2012-04-19T09:09:13Z

(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.

@dlangBugzillaToGithub
Copy link
Author

dlang-bugzilla (@CyberShadow) commented on 2012-04-19T09:10:28Z

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%.

@dlangBugzillaToGithub
Copy link
Author

lovelydear commented on 2012-04-19T09:19:52Z

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.

@dlangBugzillaToGithub
Copy link
Author

bugzilla (@WalterBright) commented on 2012-04-19T11:23:55Z

(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.

@dlangBugzillaToGithub
Copy link
Author

dlang-bugzilla (@CyberShadow) commented on 2012-04-19T11:32:02Z

(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

@dlangBugzillaToGithub
Copy link
Author

bugzilla (@WalterBright) commented on 2012-04-19T12:15:09Z

I have it fixed in snn.lib now. You can pick it up here:

ftp://ftp.digitalmars.com/dmc.zip

@dlangBugzillaToGithub
Copy link
Author

dlang-bugzilla (@CyberShadow) commented on 2014-01-28T01:52:42Z

(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

@dlangBugzillaToGithub
Copy link
Author

bugzilla (@WalterBright) commented on 2019-12-12T16:58:52Z

Is this still not fixed?

@LightBender LightBender removed the P3 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch:x86_64 Issues specific to x86_64 OS:Windows Issues Specific to Windows Severity:Normal
Projects
None yet
Development

No branches or pull requests

2 participants