mkstemp

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 for os.open() states: To wrap a file descriptor in a "file object", use fdopen(). ...

[c++] 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 and some other systems, you can create an std::ofstream from a file descriptor, but my c...

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 with fprintf()? ...

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 failed"); } else { close(fileDescriptor); NSURL *url = [NSURL URLWithString:[NSSt...