1*61180Sbostic.\" Copyright (c) 1989, 1991, 1993 2*61180Sbostic.\" The Regents of the University of California. All rights reserved. 320352Smckusick.\" 443571Strent.\" %sccs.include.redist.man% 539308Sbostic.\" 6*61180Sbostic.\" @(#)mktemp.3 8.1 (Berkeley) 06/04/93 739308Sbostic.\" 848351Scael.Dd 948351Scael.Dt MKTEMP 3 1048351Scael.Os 1148351Scael.Sh NAME 1248351Scael.Nm mktemp 1348351Scael.Nd make temporary file name (unique) 1448351Scael.Sh SYNOPSIS 1548351Scael.Fd #include <unistd.h> 1648351Scael.Ft char * 1748351Scael.Fn mktemp "char *template" 1848351Scael.Ft int 1948351Scael.Fn mkstemp "char *template" 2048351Scael.Sh DESCRIPTION 2148351ScaelThe 2248351Scael.Fn mktemp 2348351Scaelfunction 2448351Scaeltakes the given file name template and overwrites a portion of it 2548351Scaelto create a file name. 2648351ScaelThis file name is unique and suitable for use 2748351Scaelby the application. 2848351ScaelThe template may be any file name with some number of 2948351Scael.Ql X Ns s 3048351Scaelappended 3148351Scaelto it, for example 3248351Scael.Pa /tmp/temp.XXXX . 3348351ScaelThe trailing 3448351Scael.Ql X Ns s 3548351Scaelare replaced with the current process number and/or a 3639308Sbosticunique letter combination. 3739308SbosticThe number of unique file names 3848351Scael.Fn mktemp 3948351Scaelcan return depends on the number of 4048351Scael.Ql X Ns s 4148351Scaelprovided; six 4248351Scael.Ql X Ns s 4348351Scaelwill 4439308Sbosticresult in 4548351Scael.Fn mktemp 4639308Sbostictesting roughly 26 ** 6 combinations. 4748351Scael.Pp 4848351ScaelThe 4948351Scael.Fn mkstemp 5048351Scaelfunction 5139308Sbosticmakes the same replacement to the template and creates the template file, 5239308Sbosticmode 0600, returning a file descriptor opened for reading and writing. 5339308SbosticThis avoids the race between testing for a file's existence and opening it 5439308Sbosticfor use. 5548351Scael.Sh RETURN VALUES 5648351ScaelThe 5748351Scael.Fn mktemp 5848351Scaelfunction 5948351Scaelreturns a pointer to the template on success and 6048351Scael.Dv NULL 6148351Scaelon failure. 6248351ScaelThe 6348351Scael.Fn mkstemp 6448351Scaelfunction 6548351Scaelreturns \-1 if no suitable file could be created. 6648351ScaelIf either call fails an error code is placed in the global variable 6748351Scael.Va errno . 6848351Scael.Sh ERRORS 6948351ScaelThe 7048351Scael.Fn mktemp 7139308Sbosticand 7248351Scael.Fn mkstemp 7348351Scaelfunctions 7439308Sbosticmay set 7548351Scael.Va errno 7639308Sbosticto one of the following values: 7748351Scael.Bl -tag -width [ENOTDIR] 7848351Scael.It Bq Er ENOTDIR 7939308SbosticThe pathname portion of the template is not an existing directory. 8048351Scael.El 8148351Scael.Pp 8248351ScaelThe 8348351Scael.Fn mktemp 8439308Sbosticand 8548351Scael.Fn mkstemp 8648351Scaelfunctions 8739308Sbosticmay also set 8848351Scael.Va errno 8939308Sbosticto any value specified by the 9048351Scael.Xr stat 2 9139308Sbosticfunction. 9248351Scael.Pp 9348351ScaelThe 9448351Scael.Fn mkstemp 9548351Scaelfunction 9639308Sbosticmay also set 9748351Scael.Va errno 9839308Sbosticto any value specified by the 9948351Scael.Xr open 2 10039308Sbosticfunction. 10148351Scael.Sh SEE ALSO 10248351Scael.Xr chmod 2 , 10348351Scael.Xr getpid 2 , 10448351Scael.Xr open 2 , 10548351Scael.Xr stat 2 10648351Scael.Sh HISTORY 10748351ScaelA 10848351Scael.Nm mktemp 10948351Scaelfunction appeared in 11048351Scael.At v7 . 111