1mktemp(3C)               Standard C Library Functions               mktemp(3C)
2
3
4

NAME

6       mktemp - make a unique file name  from a template
7

SYNOPSIS

9       #include <stdlib.h>
10
11       char *mktemp(char *template);
12
13

DESCRIPTION

15       The mktemp() function replaces the contents of the string pointed to by
16       template with a unique file name, and returns template. The  string  in
17       template  should look like a file name with six trailing 'X's; mktemp()
18       will replace the 'X's with a character string that can be used to  cre‐
19       ate  a  unique  file  name. Only 26 unique file names per thread can be
20       created for each unique template.
21

RETURN VALUES

23       The mktemp() function returns the pointer template. If  a  unique  name
24       cannot be created, template points to a null string.
25

ERRORS

27       No errors are defined.
28

EXAMPLES

30       Example 1 Generate a filename.
31
32
33       The  following  example  replaces the contents of the "template" string
34       with a 10-character filename beginning with the characters  "file"  and
35       returns  a pointer to the "template" string that contains the new file‐
36       name.
37
38
39         #include <stdlib.h>
40         ...
41         char *template = "/tmp/fileXXXXXX";
42         char *ptr;
43         ptr = mktemp(template);
44
45

USAGE

47       Between the time a pathname is created and the file opened, it is  pos‐
48       sible  for  some other process to create a file with the same name. The
49       mkstemp(3C) function avoids this problem and  is  preferred  over  this
50       function.
51

ATTRIBUTES

53       See attributes(5) for descriptions of the following attributes:
54
55
56
57
58       ┌─────────────────────────────┬─────────────────────────────┐
59       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
60       ├─────────────────────────────┼─────────────────────────────┤
61       │Interface Stability          │Standard                     │
62       ├─────────────────────────────┼─────────────────────────────┤
63       │MT-Level                     │Safe                         │
64       └─────────────────────────────┴─────────────────────────────┘
65

SEE ALSO

67       mkstemp(3C), tmpfile(3C), tmpnam(3C), attributes(5), standards(5)
68
69
70
71SunOS 5.11                        15 Sep 2004                       mktemp(3C)
Impressum