GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::tmpnam(3) C++ Standard Libary std::tmpnam(3)

std::tmpnam - std::tmpnam


Defined in header <cstdio>
char* tmpnam( char* filename );


Creates a unique filename that does not name a currently existing file, and stores
it in the character string pointed to by filename. The function is capable of
generating up to TMP_MAX of unique filenames, but some or all of them may already be
in use, and thus not suitable return values.


std::tmpnam modifies static state and is not required to be thread-safe.


pointer to the character array capable of holding at least L_tmpnam
filename - bytes, to be used as a result buffer. If a null pointer is passed, a
pointer to an internal static buffer is returned.


filename if filename was not a null pointer. Otherwise a pointer to an internal
static buffer is returned. If no suitable filename can be generated, a null pointer
is returned.


Although the names generated by std::tmpnam are difficult to guess, it is possible
that a file with that name is created by another process between the moment
std::tmpnam returns and the moment this program attempts to use the returned name to
create a file. The standard function std::tmpfile and the POSIX function mkstemp do
not have this problem (creating a unique directory using only the standard C library
still requires the use of tmpnam).


POSIX systems additionally define the similarly named function tempnam, which offers
the choice of a directory (which defaults to the optionally defined macro P_tmpdir).

// Run this code


#include <iostream>
#include <cstdio>
#include <string>


int main()
{
std::string name1 = std::tmpnam(nullptr);
std::cout << "temporary file name: " << name1 << '\n';


char name2[L_tmpnam];
if (std::tmpnam(name2)) {
std::cout << "temporary file name: " << name2 << '\n';
}
}


temporary file name: /tmp/fileDjwifs
temporary file name: /tmp/fileEv2bfW


tmpfile creates and opens a temporary, auto-removing file
(function)
temp_directory_path returns a directory suitable for temporary files
(C++17) (function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.