1MKTEMP(3)                  Linux Programmer's Manual                 MKTEMP(3)
2
3
4

NAME

6       mktemp - make a unique temporary filename
7

SYNOPSIS

9       #include <stdlib.h>
10
11       char *mktemp(char *template);
12

DESCRIPTION

14       The  mktemp()  function generates a unique temporary filename from tem‐
15       plate.  The last six characters of template must be  XXXXXX  and  these
16       are  replaced  with  a  string that makes the filename unique. Since it
17       will be modified, template must not be a string constant, but should be
18       declared as a character array.
19

RETURN VALUE

21       The  mktemp()  function  returns NULL on error (template did not end in
22       XXXXXX) and template otherwise.  If the call was successful,  the  last
23       six  bytes  of  template will have been modified in such a way that the
24       resulting name is unique (does not exist  already).  If  the  call  was
25       unsuccessful, template is made an empty string.
26

ERRORS

28       EINVAL The last six characters of template were not XXXXXX.
29

CONFORMING TO

31       4.3BSD, POSIX.1-2001.
32

NOTE

34       The prototype is in <unistd.h> for libc4, libc5, glibc1; glibc2 follows
35       the Single Unix Specification and has the prototype in <stdlib.h>.
36

BUGS

38       Never use mktemp(). Some  implementations  follow  4.3BSD  and  replace
39       XXXXXX  by  the current process ID and a single letter, so that at most
40       26 different names can be returned.  Since on the one  hand  the  names
41       are  easy to guess, and on the other hand there is a race between test‐
42       ing whether the name exists and opening the file, every use of mktemp()
43       is a security risk.  The race is avoided by mkstemp(3).
44

SEE ALSO

46       mkstemp(3), tempnam(3), tmpfile(3), tmpnam(3)
47
48
49
50GNU                               1993-04-03                         MKTEMP(3)
Impressum