1MKSTEMP(3P) POSIX Programmer's Manual MKSTEMP(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 mkstemp - make a unique filename
13
15 #include <stdlib.h>
16
17 int mkstemp(char *template);
18
19
21 The mkstemp() function shall replace the contents of the string pointed
22 to by template by a unique filename, and return a file descriptor for
23 the file open for reading and writing. The function thus prevents any
24 possible race condition between testing whether the file exists and
25 opening it for use. The string in template should look like a filename
26 with six trailing 'X' s; mkstemp() replaces each 'X' with a character
27 from the portable filename character set. The characters are chosen
28 such that the resulting name does not duplicate the name of an existing
29 file at the time of a call to mkstemp().
30
32 Upon successful completion, mkstemp() shall return an open file
33 descriptor. Otherwise, -1 shall be returned if no suitable file could
34 be created.
35
37 No errors are defined.
38
39 The following sections are informative.
40
42 Generating a Filename
43 The following example creates a file with a 10-character name beginning
44 with the characters "file" and opens the file for reading and writing.
45 The value returned as the value of fd is a file descriptor that identiā
46 fies the file.
47
48
49 #include <stdlib.h>
50 ...
51 char template[] = "/tmp/fileXXXXXX";
52 int fd;
53
54
55 fd = mkstemp(template);
56
58 It is possible to run out of letters.
59
60 The mkstemp() function need not check to determine whether the filename
61 part of template exceeds the maximum allowable filename length.
62
64 None.
65
67 None.
68
70 getpid(), open(), tmpfile(), tmpnam(), the Base Definitions volume of
71 IEEE Std 1003.1-2001, <stdlib.h>
72
74 Portions of this text are reprinted and reproduced in electronic form
75 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
76 -- Portable Operating System Interface (POSIX), The Open Group Base
77 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
78 Electrical and Electronics Engineers, Inc and The Open Group. In the
79 event of any discrepancy between this version and the original IEEE and
80 The Open Group Standard, the original IEEE and The Open Group Standard
81 is the referee document. The original Standard can be obtained online
82 at http://www.opengroup.org/unix/online.html .
83
84
85
86IEEE/The Open Group 2003 MKSTEMP(3P)