It returns a file descriptor for an already opened file.
Comment #6 by kdevel — 2024-01-06T06:52:59Z
(In reply to Walter Bright from comment #5)
> It returns a file descriptor for an already opened file.
The descriptor is unused and can be safely closed (or the FILE* ptr fclosed after using fdopen). Using mkstemp is how to create a named temporary file lege
artis in GNU/Linux [5].
The actual filename is in the writable template-buffer given as parameter to mkstemp. The preprocessor will put its output into that file.
I was under the impression that not the POSIX but the Windows version could pose
problems here?
[5] sec 2.2.2. (p. 7) of Ulrich Drepper: Defensive Programming for Red Hat
Enterprise Linux (and What To Do If Something Goes Wrong)
http://people.redhat.com/drepper/defprogramming.pdf
Comment #7 by ibuclaw — 2024-01-06T22:27:56Z
(In reply to Walter Bright from comment #5)
> It returns a file descriptor for an already opened file.
The passed string is an out parameter as well.
@kdevel one convenience of tmpnam is that you don't have to worry about where the $TEMP directory is located for the vagary of supported platforms.
> Maybe I just need to write our own tmpnam() function.
The generic-ish implementation should be simple enough, could return a slice too instead of a pointer.
Comment #8 by dlang-bot — 2024-02-01T04:21:23Z
@WalterBright created dlang/dmd pull request #16126 "fix bugzilla Issue 24315 - dmd/cpreprocess.d:87: warning: use of tmpn…" fixing this issue:
- fix bugzilla Issue 24315 - dmd/cpreprocess.d:87: warning: use of tmpnam is dangerous use mkstemp
https://github.com/dlang/dmd/pull/16126
Comment #9 by dlang-bot — 2024-02-02T10:07:15Z
dlang/dmd pull request #16126 "fix bugzilla Issue 24315 - dmd/cpreprocess.d:87: warning: use of tmpn…" was merged into master:
- 01b8d5d8534d0ba1a6cbe516040fa70221320344 by Walter Bright:
fix bugzilla Issue 24315 - dmd/cpreprocess.d:87: warning: use of tmpnam is dangerous use mkstemp
https://github.com/dlang/dmd/pull/16126