std::tmpnam
De cppreference.com
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Déclaré dans l'en-tête <cstdio>
|
||
char* tmpnam( char* filename ); |
||
Crée un nom de fichier unique qui ne nomme pas un fichier existant actuellement, et le stocke dans la chaîne de caractères pointée par
filename
. La fonction est capable de générer jusqu'à TMP_MAX des noms de fichiers uniques, mais tout ou partie d'entre eux peut-être déjà en cours d'utilisation, et donc pas les valeurs de retour appropriés . Original:
Creates an 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. The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Sommaire |
[modifier] Paramètres
filename | - | pointeur vers le tableau de caractères pouvant contenir au moins L_tmpnam octets, pour être utilisé comme un buffer de résultat. Si
NULL est passé, un pointeur vers une mémoire tampon interne statique est retourné .Original: pointer to the character array capable of holding at least L_tmpnam bytes, to be used as a result buffer. If NULL is passed, a pointer to an internal static buffer is returned.The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[modifier] Retourne la valeur
filename
si filename
n'était pas NULL. Sinon, un pointeur vers un tampon interne statique est renvoyé. Si aucun fichier approprié peut être générée, est renvoyé NULL .Original:
filename
if filename
was not NULL. Otherwise a pointer to an internal static buffer is returned. If no suitable filename can be generated, NULL is returned.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifier] Notes
Lorsqu'il est appelé avec l'argument de pointeur nul, cette fonction modifie un objet global. Si un autre thread appelle
std::tmpnam
avec l'argument de pointeur NULL dans le même temps, le comportement est indéfini due à une race de données .Original:
When called with null pointer argument, this function modifies a global object. If another thread calls
std::tmpnam
with null pointer argument at the same time, the behavior is undefined due to a data race.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Bien que les noms générés par
std::tmpnam
sont difficiles à deviner, il est possible qu'un fichier portant ce nom est créé par un autre processus entre les rendements std::tmpnam
instant et le moment de ce programme tente d'utiliser le nom renvoyé pour créer un fichier. Le std::tmpfile fonction standard et la fonction POSIX mkstemp n'ont pas ce problème .Original:
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.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifier] Exemple
#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'; }
Résultat possible :
temporary file name: /tmp/fileDjwifs temporary file name: /tmp/fileEv2bfW
[modifier] Voir aussi
crée et ouvre un temporaire, auto-suppression du fichier Original: creates and opens a temporary, auto-removing file The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction) | |
C documentation for tmpnam
|