1mkstemp(3C) Standard C Library Functions mkstemp(3C)
2
3
4
6 mkstemp, mkstemps, mkdtemp - make a unique file name from a template
7 and open the file
8
10 #include <stdlib.h>
11
12 int mkstemp(char *template);
13
14
15 int mkstemps(char *template, int slen);
16
17
18 char *mkdtemp(char *template);
19
20
22 The mkstemp() function replaces the contents of the string pointed to
23 by template by a unique file name, and returns a file descriptor for
24 the file open for reading and writing. The function thus prevents any
25 possible race condition between testing whether the file exists and
26 opening it for use. The string in template should look like a file name
27 with six trailing 'X's; mkstemp() replaces each 'X' with a character
28 from the portable file name character set. The characters are chosen
29 such that the resulting name does not duplicate the name of an existing
30 file.
31
32
33 The mkstemps() function behaves the same as mkstemp(), except it per‐
34 mits a suffix to exist in the template. The template should be of the
35 form /tmp/tmpXXXXXXsuffix. The slen parameter specifies the length of
36 the suffix string.
37
38
39 The mkdtemp() function makes the same replacement to the template as in
40 mktemp(3C) and creates the template directory using mkdir(2), passing a
41 mode argument of 0700.
42
44 Upon successful completion, mkstemp() returns an open file descriptor.
45 Otherwise −1 is returned if no suitable file could be created.
46
48 The mkstemp(), mkstemps(), and mkdtemp() functions can set errno to the
49 same values as lstat(2).
50
51
52 The mkstemp() and mkstemps() functions can set errno to the same values
53 as open(2).
54
55
56 The mkdtemp() function can set errno to the same values as mkdir(2).
57
59 It is possible to run out of letters.
60
61
62 The mkstemp() function does not check to determine whether the file
63 name part of template exceeds the maximum allowable file name length.
64
65
66 The tmpfile(3C) function is preferred over this function.
67
68
69 The mkstemp() function is frequently used to create a temporary file
70 that will be removed by the application before the application termi‐
71 nates.
72
73
74 The mkstemp() function has a transitional interface for 64-bit file
75 offsets. See lf64(5).
76
78 See attributes(5) for descriptions of the following attributes:
79
80
81
82
83 ┌─────────────────────────────┬─────────────────────────────┐
84 │ATTRIBUTE TYPE │ATTRIBUTE VALUE │
85 ├─────────────────────────────┼─────────────────────────────┤
86 │Interface Stability │See below. │
87 └─────────────────────────────┴─────────────────────────────┘
88
89
90 The mkstemp() function is Standard. The mkstemps() and mkdtemp() func‐
91 tions are Stable.
92
94 getpid(2), lstat(2), mkdir(2), open(2), tmpfile(3C), mktemp(3C),
95 attributes(5), lf64(5), standards(5)
96
97
98
99SunOS 5.11 22 Feb 2006 mkstemp(3C)