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