xref: /freebsd/lib/libc/stdio/mktemp.3 (revision 58f0484fa251c266ede97b591b499fe3dd4f578e)
158f0484fSRodney W. Grimes.\" Copyright (c) 1989, 1991, 1993
258f0484fSRodney W. Grimes.\"	The Regents of the University of California.  All rights reserved.
358f0484fSRodney W. Grimes.\"
458f0484fSRodney W. Grimes.\" Redistribution and use in source and binary forms, with or without
558f0484fSRodney W. Grimes.\" modification, are permitted provided that the following conditions
658f0484fSRodney W. Grimes.\" are met:
758f0484fSRodney W. Grimes.\" 1. Redistributions of source code must retain the above copyright
858f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer.
958f0484fSRodney W. Grimes.\" 2. Redistributions in binary form must reproduce the above copyright
1058f0484fSRodney W. Grimes.\"    notice, this list of conditions and the following disclaimer in the
1158f0484fSRodney W. Grimes.\"    documentation and/or other materials provided with the distribution.
1258f0484fSRodney W. Grimes.\" 3. All advertising materials mentioning features or use of this software
1358f0484fSRodney W. Grimes.\"    must display the following acknowledgement:
1458f0484fSRodney W. Grimes.\"	This product includes software developed by the University of
1558f0484fSRodney W. Grimes.\"	California, Berkeley and its contributors.
1658f0484fSRodney W. Grimes.\" 4. Neither the name of the University nor the names of its contributors
1758f0484fSRodney W. Grimes.\"    may be used to endorse or promote products derived from this software
1858f0484fSRodney W. Grimes.\"    without specific prior written permission.
1958f0484fSRodney W. Grimes.\"
2058f0484fSRodney W. Grimes.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2158f0484fSRodney W. Grimes.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2258f0484fSRodney W. Grimes.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2358f0484fSRodney W. Grimes.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2458f0484fSRodney W. Grimes.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2558f0484fSRodney W. Grimes.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2658f0484fSRodney W. Grimes.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2758f0484fSRodney W. Grimes.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2858f0484fSRodney W. Grimes.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2958f0484fSRodney W. Grimes.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3058f0484fSRodney W. Grimes.\" SUCH DAMAGE.
3158f0484fSRodney W. Grimes.\"
3258f0484fSRodney W. Grimes.\"     @(#)mktemp.3	8.1 (Berkeley) 6/4/93
3358f0484fSRodney W. Grimes.\"
3458f0484fSRodney W. Grimes.Dd June 4, 1993
3558f0484fSRodney W. Grimes.Dt MKTEMP 3
3658f0484fSRodney W. Grimes.Os
3758f0484fSRodney W. Grimes.Sh NAME
3858f0484fSRodney W. Grimes.Nm mktemp
3958f0484fSRodney W. Grimes.Nd make temporary file name (unique)
4058f0484fSRodney W. Grimes.Sh SYNOPSIS
4158f0484fSRodney W. Grimes.Fd #include <unistd.h>
4258f0484fSRodney W. Grimes.Ft char *
4358f0484fSRodney W. Grimes.Fn mktemp "char *template"
4458f0484fSRodney W. Grimes.Ft int
4558f0484fSRodney W. Grimes.Fn mkstemp "char *template"
4658f0484fSRodney W. Grimes.Sh DESCRIPTION
4758f0484fSRodney W. GrimesThe
4858f0484fSRodney W. Grimes.Fn mktemp
4958f0484fSRodney W. Grimesfunction
5058f0484fSRodney W. Grimestakes the given file name template and overwrites a portion of it
5158f0484fSRodney W. Grimesto create a file name.
5258f0484fSRodney W. GrimesThis file name is unique and suitable for use
5358f0484fSRodney W. Grimesby the application.
5458f0484fSRodney W. GrimesThe template may be any file name with some number of
5558f0484fSRodney W. Grimes.Ql X Ns s
5658f0484fSRodney W. Grimesappended
5758f0484fSRodney W. Grimesto it, for example
5858f0484fSRodney W. Grimes.Pa /tmp/temp.XXXX .
5958f0484fSRodney W. GrimesThe trailing
6058f0484fSRodney W. Grimes.Ql X Ns s
6158f0484fSRodney W. Grimesare replaced with the current process number and/or a
6258f0484fSRodney W. Grimesunique letter combination.
6358f0484fSRodney W. GrimesThe number of unique file names
6458f0484fSRodney W. Grimes.Fn mktemp
6558f0484fSRodney W. Grimescan return depends on the number of
6658f0484fSRodney W. Grimes.Ql X Ns s
6758f0484fSRodney W. Grimesprovided; six
6858f0484fSRodney W. Grimes.Ql X Ns s
6958f0484fSRodney W. Grimeswill
7058f0484fSRodney W. Grimesresult in
7158f0484fSRodney W. Grimes.Fn mktemp
7258f0484fSRodney W. Grimestesting roughly 26 ** 6 combinations.
7358f0484fSRodney W. Grimes.Pp
7458f0484fSRodney W. GrimesThe
7558f0484fSRodney W. Grimes.Fn mkstemp
7658f0484fSRodney W. Grimesfunction
7758f0484fSRodney W. Grimesmakes the same replacement to the template and creates the template file,
7858f0484fSRodney W. Grimesmode 0600, returning a file descriptor opened for reading and writing.
7958f0484fSRodney W. GrimesThis avoids the race between testing for a file's existence and opening it
8058f0484fSRodney W. Grimesfor use.
8158f0484fSRodney W. Grimes.Sh RETURN VALUES
8258f0484fSRodney W. GrimesThe
8358f0484fSRodney W. Grimes.Fn mktemp
8458f0484fSRodney W. Grimesfunction
8558f0484fSRodney W. Grimesreturns a pointer to the template on success and
8658f0484fSRodney W. Grimes.Dv NULL
8758f0484fSRodney W. Grimeson failure.
8858f0484fSRodney W. GrimesThe
8958f0484fSRodney W. Grimes.Fn mkstemp
9058f0484fSRodney W. Grimesfunction
9158f0484fSRodney W. Grimesreturns \-1 if no suitable file could be created.
9258f0484fSRodney W. GrimesIf either call fails an error code is placed in the global variable
9358f0484fSRodney W. Grimes.Va errno .
9458f0484fSRodney W. Grimes.Sh ERRORS
9558f0484fSRodney W. GrimesThe
9658f0484fSRodney W. Grimes.Fn mktemp
9758f0484fSRodney W. Grimesand
9858f0484fSRodney W. Grimes.Fn mkstemp
9958f0484fSRodney W. Grimesfunctions
10058f0484fSRodney W. Grimesmay set
10158f0484fSRodney W. Grimes.Va errno
10258f0484fSRodney W. Grimesto one of the following values:
10358f0484fSRodney W. Grimes.Bl -tag -width [ENOTDIR]
10458f0484fSRodney W. Grimes.It Bq Er ENOTDIR
10558f0484fSRodney W. GrimesThe pathname portion of the template is not an existing directory.
10658f0484fSRodney W. Grimes.El
10758f0484fSRodney W. Grimes.Pp
10858f0484fSRodney W. GrimesThe
10958f0484fSRodney W. Grimes.Fn mktemp
11058f0484fSRodney W. Grimesand
11158f0484fSRodney W. Grimes.Fn mkstemp
11258f0484fSRodney W. Grimesfunctions
11358f0484fSRodney W. Grimesmay also set
11458f0484fSRodney W. Grimes.Va errno
11558f0484fSRodney W. Grimesto any value specified by the
11658f0484fSRodney W. Grimes.Xr stat 2
11758f0484fSRodney W. Grimesfunction.
11858f0484fSRodney W. Grimes.Pp
11958f0484fSRodney W. GrimesThe
12058f0484fSRodney W. Grimes.Fn mkstemp
12158f0484fSRodney W. Grimesfunction
12258f0484fSRodney W. Grimesmay also set
12358f0484fSRodney W. Grimes.Va errno
12458f0484fSRodney W. Grimesto any value specified by the
12558f0484fSRodney W. Grimes.Xr open 2
12658f0484fSRodney W. Grimesfunction.
12758f0484fSRodney W. Grimes.Sh SEE ALSO
12858f0484fSRodney W. Grimes.Xr chmod 2 ,
12958f0484fSRodney W. Grimes.Xr getpid 2 ,
13058f0484fSRodney W. Grimes.Xr open 2 ,
13158f0484fSRodney W. Grimes.Xr stat 2
13258f0484fSRodney W. Grimes.Sh HISTORY
13358f0484fSRodney W. GrimesA
13458f0484fSRodney W. Grimes.Nm mktemp
13558f0484fSRodney W. Grimesfunction appeared in
13658f0484fSRodney W. Grimes.At v7 .
137