BSD 4_3_Reno release
[unix-history] / usr / src / lib / libc / gen / mktemp.3
CommitLineData
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 23mktemp \- create a unique file name
93138961
KM
24.SH SYNOPSIS
25.nf
daa9b7ca
KB
26.ft B
27char *
28mktemp(template)
29char *template;
78396556 30.sp
daa9b7ca
KB
31mkstemp(template)
32char *template;
33.ft R
93138961
KM
34.fi
35.SH DESCRIPTION
daa9b7ca
KB
36.I Mktemp
37takes a file name template and overwrites it to create a unique file
38name for use by the application.
39The template may be any file name with some number of X's appended
40to it, for example ``/tmp/temp.XXXX''.
41The trailing X's are replaced with the current process number and/or a
42unique letter combination.
43The number of unique file names
44.I mktemp
45can return depends on the number of X's provided; six X's will
46result in
47.I mktemp
48testing roughly 26 ** 6 combinations.
49.PP
50.I Mkstemp
51makes the same replacement to the template and creates the template file,
52mode 0600, returning a file descriptor opened for reading and writing.
53This avoids the race between testing for a file's existence and opening it
54for use.
63ab58b9 55.SH "RETURN VALUE"
daa9b7ca
KB
56.I Mktemp
57returns a pointer to the template on success and NULL on failure.
58.I Mkstemp
59returns -1 if no suitable file could be created.
63ab58b9
KB
60If either call fails an error code is placed in the global location
61.IR errno .
daa9b7ca
KB
62.SH ERRORS
63.I Mktemp
64and
65.I mkstemp
66may set
67.I errno
68to one of the following values:
69.TP
70[ENOTDIR]
71The pathname portion of the template is not an existing directory.
72.PP
73.I Mktemp
74and
75.I mkstemp
76may also set
77.I errno
78to any value specified by the
79.IR stat (2)
80function.
81.I Mkstemp
82may also set
83.I errno
84to any value specified by the
85.IR open (2)
86function.
93138961 87.SH "SEE ALSO"
afd0a535 88chmod(2), getpid(2), open(2), stat(2)