std::tmpnam
Da 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. |
Definido no cabeçalho <cstdio>
|
||
char* tmpnam( char* filename ); |
||
Cria um nome de arquivo único que não nomeia um arquivo atualmente existente, e armazena-lo na cadeia de caracteres apontada por
filename
. A função é capaz de gerar até TMP_MAX de nomes de ficheiros originais, mas alguns ou todos eles podem já estar em uso, e não os valores de retorno, assim, adequados. 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.
Índice |
[editar] Parâmetros
filename | - | ponteiro para o conjunto de caracteres capazes de segurar os bytes menos L_tmpnam, para ser usado como um buffer de resultado. Se
NULL é passado, um ponteiro para um buffer interno estático é retornado .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. |
[editar] Valor de retorno
filename
se filename
não era NULL. Caso contrário, um ponteiro para um buffer interno estático é retornado. Se nenhum nome adequado pode ser gerado, NULL é retornado.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.
[editar] Notas
Quando chamado com o argumento de ponteiro nulo, esta função modifica um objeto global. Se outra thread chama
std::tmpnam
com o argumento de ponteiro nulo, ao mesmo tempo, o comportamento é indefinido devido a uma corrida de dados.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.
Embora os nomes gerados por
std::tmpnam
são difíceis de adivinhar, é possível que um arquivo com esse nome é criado por outro processo entre os retornos momento std::tmpnam
eo momento este programa tenta usar o nome retornado para criar um arquivo. O std::tmpfile função padrão ea função POSIX mkstemp não tem esse problema.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.
[editar] Exemplo
#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'; }
Potencial saída:
temporary file name: /tmp/fileDjwifs temporary file name: /tmp/fileEv2bfW
[editar] Veja também
cria e abre um temporário, arquivo auto de remoção 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. (função) | |
Documentação C para tmpnam
|