Questions tagged [mkstemp]

The mkstemp() function generates a unique temporary filename. Part of glibc.

The mkstemp() function generates a unique temporary filename from template, creates and opens the file, and returns an open file descriptor for the file.

more info at the man page

30 questions
96
votes
3 answers

How to get a FILE pointer from a file descriptor?

I'm playing around with mkstemp(), which provides a file descriptor, but I want to generate formatted output via fprintf(). Is there an easy way to transform the file descriptor provided by mkstemp() into a FILE * structure that is suitable for use…
BD at Rivenhill
  • 12,395
  • 10
  • 46
  • 49
61
votes
6 answers

Python - How do I convert "an OS-level handle to an open file" to a file object?

tempfile.mkstemp() returns: a tuple containing an OS-level handle to an open file (as would be returned by os.open()) and the absolute pathname of that file, in that order. How do I convert that OS-level handle to a file object? The documentation…
Daryl Spitzer
  • 143,156
  • 76
  • 154
  • 173
37
votes
4 answers

How to create a std::ofstream to a temp file?

Okay, mkstemp is the preferred way to create a temp file in POSIX. But it opens the file and returns an int, which is a file descriptor. From that I can only create a FILE*, but not an std::ofstream, which I would prefer in C++. (Apparently, on AIX…
Frank
  • 64,140
  • 93
  • 237
  • 324
25
votes
4 answers

Python write in mkstemp() file

I am creating a tmp file by using : from tempfile import mkstemp I am trying to write in this file : tmp_file = mkstemp() file = open(tmp_file, 'w') file.write('TEST\n') Indeed I close the file and do it proper but when I try to cat the tmp file,…
Steeven_b
  • 747
  • 2
  • 10
  • 22
13
votes
3 answers

mkstemp() implementation for win32

Can anybody point me to the code that implements mkstemp() (C/C++) on Win32, or very close analog? Must be race-free. It's supposed to look like #include #include // port of mkstemp() to win32. race-free. // behaviour as…
Andrei
  • 8,606
  • 10
  • 35
  • 43
12
votes
3 answers

What is the C++ standard library equivalent for mkstemp?

I am transitioning a program that uses temporary files from POSIX FILE to C++ standard library iostreams. What's the correct alternative to mkstemp?
vy32
  • 28,461
  • 37
  • 122
  • 246
5
votes
2 answers

Get the file name that was created by mkstemp()

Is it possible to get the file name (and path) from a call to mkstemp()? And if "yes", how?
alexandernst
  • 14,352
  • 22
  • 97
  • 197
3
votes
1 answer

Using the filename generated from mkstemp

The mkstemp() function generates a unique temporary filename from template, creates and opens the file, and returns an open file descriptor for the file. The last six characters of template must be "XXXXXX" and these are replaced with a string that…
mcorley
  • 767
  • 12
  • 21
3
votes
2 answers

tempfile.mkstemp permissions settings

I am using tempfile.mkstemp to generate a random available filename and write some content with os.fdopen. I then pass the filename to a task via celery. This task opens the file, processes the content, and finally removes the file. In testing this…
PyPingu
  • 1,697
  • 1
  • 8
  • 21
3
votes
1 answer

Python: os.tmpfile or tempfile.mkstemp

I want to open a external configuration file and present it to the user in an editor. The solution I am thinking about is to create a temporary file and copy the content of the original file to it. The temporary file will then be opened for editing…
devhallo
  • 337
  • 3
  • 13
3
votes
1 answer

MPI-aware mkstemp(3) for use with MPI_FILE_OPEN?

I'd like to generate a unique filename within an MPI application. Reading "Advice to implementors" under MPI_FILE_OPEN in version 2.2 of the the specification indicates that filenames like uriPrefix:foo/bar/baz in addition to just the usual…
Rhys Ulerich
  • 1,242
  • 1
  • 12
  • 28
2
votes
2 answers

Cannot create temporary file - mkstemp: No such file or directory

In centos when installing package yum install it didn't work & throws the error as Cannot create temporary file - mkstemp: No such file or directory
2
votes
1 answer

FreeBSD jails mkstemp failed

I'm trying to install some stuff in my jails with this set up: I have make my own flavor of jails by following this howto: FreeBSD forum Everything worked fine for me so far, I have mounted /usr/ports with fstab to the jail, started the jail and…
2
votes
1 answer

Can't delete a file created by mkstemp() on Mac OS X

Apparently, NSFileManager is unable to delete files created by mkstemp(). Here's some test code to demonstrate this: char pathCString[] = "/tmp/temp.XXXXXX"; int fileDescriptor = mkstemp(pathCString); if (fileDescriptor == -1) { NSLog(@"mkstemp…
splicer
  • 5,344
  • 4
  • 42
  • 47
2
votes
2 answers

changing file permissions of default mkstemp

I call the following code in C: fileCreatefd = mkstemp(fileName); I see that the file is created with permissions 600 (-rw-------). I want to create this temp file as -rw-rw-rw- I tried playing around with umask but that only applies a mask over…
Abhishek
  • 275
  • 7
  • 18
1
2