Commit | Line | Data |
---|---|---|
daa9b7ca KB |
1 | .\" Copyright (c) 1989 The Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
91cff1e1 | 4 | .\" %sccs.include.redist.man% |
daa9b7ca | 5 | .\" |
1382c0b2 | 6 | .\" @(#)mktemp.3 6.8 (Berkeley) %G% |
93138961 | 7 | .\" |
78396556 | 8 | .TH MKTEMP 3 "" |
93138961 KM |
9 | .AT 3 |
10 | .SH NAME | |
daa9b7ca | 11 | mktemp \- create a unique file name |
93138961 KM |
12 | .SH SYNOPSIS |
13 | .nf | |
daa9b7ca | 14 | .ft B |
1382c0b2 KB |
15 | #include <unistd.h> |
16 | ||
17 | char *mktemp(char *template); | |
18 | ||
19 | int mkstemp(char *template); | |
daa9b7ca | 20 | .ft R |
93138961 KM |
21 | .fi |
22 | .SH DESCRIPTION | |
daa9b7ca KB |
23 | .I Mktemp |
24 | takes a file name template and overwrites it to create a unique file | |
25 | name for use by the application. | |
26 | The template may be any file name with some number of X's appended | |
27 | to it, for example ``/tmp/temp.XXXX''. | |
28 | The trailing X's are replaced with the current process number and/or a | |
29 | unique letter combination. | |
30 | The number of unique file names | |
31 | .I mktemp | |
32 | can return depends on the number of X's provided; six X's will | |
33 | result in | |
34 | .I mktemp | |
35 | testing roughly 26 ** 6 combinations. | |
36 | .PP | |
37 | .I Mkstemp | |
38 | makes the same replacement to the template and creates the template file, | |
39 | mode 0600, returning a file descriptor opened for reading and writing. | |
40 | This avoids the race between testing for a file's existence and opening it | |
41 | for use. | |
63ab58b9 | 42 | .SH "RETURN VALUE" |
daa9b7ca KB |
43 | .I Mktemp |
44 | returns a pointer to the template on success and NULL on failure. | |
45 | .I Mkstemp | |
46 | returns -1 if no suitable file could be created. | |
63ab58b9 KB |
47 | If either call fails an error code is placed in the global location |
48 | .IR errno . | |
daa9b7ca KB |
49 | .SH ERRORS |
50 | .I Mktemp | |
51 | and | |
52 | .I mkstemp | |
53 | may set | |
54 | .I errno | |
55 | to one of the following values: | |
56 | .TP | |
57 | [ENOTDIR] | |
58 | The pathname portion of the template is not an existing directory. | |
59 | .PP | |
60 | .I Mktemp | |
61 | and | |
62 | .I mkstemp | |
63 | may also set | |
64 | .I errno | |
65 | to any value specified by the | |
66 | .IR stat (2) | |
67 | function. | |
68 | .I Mkstemp | |
69 | may also set | |
70 | .I errno | |
71 | to any value specified by the | |
72 | .IR open (2) | |
73 | function. | |
93138961 | 74 | .SH "SEE ALSO" |
afd0a535 | 75 | chmod(2), getpid(2), open(2), stat(2) |