Commit | Line | Data |
---|---|---|
daa9b7ca KB |
1 | .\" Copyright (c) 1989 The Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
1c15e888 C |
4 | .\" Redistribution and use in source and binary forms are permitted provided |
5 | .\" that: (1) source distributions retain this entire copyright notice and | |
6 | .\" comment, and (2) distributions including binaries display the following | |
7 | .\" acknowledgement: ``This product includes software developed by the | |
8 | .\" University of California, Berkeley and its contributors'' in the | |
9 | .\" documentation or other materials provided with the distribution and in | |
10 | .\" all advertising materials mentioning features or use of this software. | |
11 | .\" Neither the name of the University nor the names of its contributors may | |
12 | .\" be used to endorse or promote products derived from this software without | |
13 | .\" specific prior written permission. | |
14 | .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED | |
15 | .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF | |
16 | .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
daa9b7ca | 17 | .\" |
1c15e888 | 18 | .\" @(#)mktemp.3 6.7 (Berkeley) 6/23/90 |
93138961 | 19 | .\" |
1c15e888 | 20 | .TH MKTEMP 3 "June 23, 1990" |
93138961 KM |
21 | .AT 3 |
22 | .SH NAME | |
daa9b7ca | 23 | mktemp \- create a unique file name |
93138961 KM |
24 | .SH SYNOPSIS |
25 | .nf | |
daa9b7ca KB |
26 | .ft B |
27 | char * | |
28 | mktemp(template) | |
29 | char *template; | |
78396556 | 30 | .sp |
daa9b7ca KB |
31 | mkstemp(template) |
32 | char *template; | |
33 | .ft R | |
93138961 KM |
34 | .fi |
35 | .SH DESCRIPTION | |
daa9b7ca KB |
36 | .I Mktemp |
37 | takes a file name template and overwrites it to create a unique file | |
38 | name for use by the application. | |
39 | The template may be any file name with some number of X's appended | |
40 | to it, for example ``/tmp/temp.XXXX''. | |
41 | The trailing X's are replaced with the current process number and/or a | |
42 | unique letter combination. | |
43 | The number of unique file names | |
44 | .I mktemp | |
45 | can return depends on the number of X's provided; six X's will | |
46 | result in | |
47 | .I mktemp | |
48 | testing roughly 26 ** 6 combinations. | |
49 | .PP | |
50 | .I Mkstemp | |
51 | makes the same replacement to the template and creates the template file, | |
52 | mode 0600, returning a file descriptor opened for reading and writing. | |
53 | This avoids the race between testing for a file's existence and opening it | |
54 | for use. | |
63ab58b9 | 55 | .SH "RETURN VALUE" |
daa9b7ca KB |
56 | .I Mktemp |
57 | returns a pointer to the template on success and NULL on failure. | |
58 | .I Mkstemp | |
59 | returns -1 if no suitable file could be created. | |
63ab58b9 KB |
60 | If either call fails an error code is placed in the global location |
61 | .IR errno . | |
daa9b7ca KB |
62 | .SH ERRORS |
63 | .I Mktemp | |
64 | and | |
65 | .I mkstemp | |
66 | may set | |
67 | .I errno | |
68 | to one of the following values: | |
69 | .TP | |
70 | [ENOTDIR] | |
71 | The pathname portion of the template is not an existing directory. | |
72 | .PP | |
73 | .I Mktemp | |
74 | and | |
75 | .I mkstemp | |
76 | may also set | |
77 | .I errno | |
78 | to any value specified by the | |
79 | .IR stat (2) | |
80 | function. | |
81 | .I Mkstemp | |
82 | may also set | |
83 | .I errno | |
84 | to any value specified by the | |
85 | .IR open (2) | |
86 | function. | |
93138961 | 87 | .SH "SEE ALSO" |
afd0a535 | 88 | chmod(2), getpid(2), open(2), stat(2) |