Namespaces
Variants
Views
Actions

Difference between revisions of "c/io/tmpnam"

From cppreference.com
< c‎ | io
m (r2.7.3) (Robot: Adding de, es, fr, it, ja, pt, ru, zh)
m (Shorten template names. Use {{lc}} where appropriate.)
Line 8: Line 8:
  
 
===Parameters===
 
===Parameters===
{{param list begin}}
+
{{par begin}}
{{param list item | filename | pointer to the character string to be used as a result buffer. If {{tt|NULL}} is passed, a pointer to an internal static buffer is returned.}}
+
{{par | filename | pointer to the character string to be used as a result buffer. If {{tt|NULL}} is passed, a pointer to an internal static buffer is returned.}}
{{param list end}}
+
{{par end}}
  
 
===Return value===
 
===Return value===
{{tt|filename}} if {{tt|filename}} was not {{c|NULL}}. Otherwise a pointer to an internal static buffer is returned. If no suitable filename can be generated, {{c|NULL}} is returned.
+
{{tt|filename}} if {{tt|filename}} was not {{lc|NULL}}. Otherwise a pointer to an internal static buffer is returned. If no suitable filename can be generated, {{lc|NULL}} is returned.
  
 
===Example===
 
===Example===
Line 42: Line 42:
  
 
===See also===
 
===See also===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list template | c/io/dcl list tmpfile}}
+
{{dsc inc | c/io/dcl list tmpfile}}
{{dcl list see cpp | cpp/io/c/tmpnam}}
+
{{dsc see cpp | cpp/io/c/tmpnam}}
{{dcl list end}}
+
{{dsc end}}
  
 
[[de:c/io/tmpnam]]
 
[[de:c/io/tmpnam]]

Revision as of 17:34, 31 May 2013

 
 
File input/output
Types and objects
Functions
File access
Direct input/output
Unformatted input/output
(C95)(C95)
(C95)
(C95)(C95)
(C95)
(C95)
Formatted input
(C99)(C99)(C99)(C11)(C11)(C11)     
Formatted output
File positioning
Error handling
Operations on files
tmpnamtmpnam_s
(C11)
 
Defined in header <stdio.h>
char *tmpnam( char *filename );

Creates an unique filename and stores it in 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 be in use in the filesystem and thus not suitable return values.

Contents

Parameters

filename - pointer to the character string to be used as a result buffer. If NULL is passed, a pointer to an internal static buffer is returned.

Return value

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.

Example

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
 
int main(int argc, char *argv[])
{
    printf("Welcome to %s\n", argv[0]);
    printf("Called with %u arguments\n", argc - 1);
 
    char buffer[L_tmpnam] = {'\0'};
    tmpnam(buffer);
    printf(buffer);
    printf("\n");
 
    printf("Goodbye!\n");
    exit(EXIT_SUCCESS);
}

Output:

Welcome to ./main_release
Called with 0 arguments
/tmp/file6HADua
Goodbye!

See also

Template:c/io/dcl list tmpfile