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

NAME

6       mkstemp - create a unique temporary file
7

SYNOPSIS

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

DESCRIPTION

14       The  mkstemp() 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. The file is
17       then created with mode read/write and permissions 0666 (glibc 2.0.6 and
18       earlier),  0600  (glibc  2.0.7  and later).  Since it will be modified,
19       template must not be a string constant, but should  be  declared  as  a
20       character  array.   The  file  is  opened with the open(2) O_EXCL flag,
21       guaranteeing that when mkstemp() returns successfully we are  the  only
22       user.
23

RETURN VALUE

25       On  success,  the mkstemp() function returns the file descriptor of the
26       temporary file.  On error, -1 is returned, and errno is  set  appropri‐
27       ately.
28

ERRORS

30       EEXIST Could  not create a unique temporary filename.  Now the contents
31              of template are undefined.
32
33       EINVAL The last six characters of template were not XXXXXX.   Now  tem‐
34              plate is unchanged.
35

NOTES

37       The  old  behaviour  (creating a file with mode 0666) may be a security
38       risk, especially since other Unix flavours use 0600, and somebody might
39       overlook this detail when porting programs.
40
41       More  generally,  the  POSIX  specification does not say anything about
42       file modes, so the application should make sure its umask is set appro‐
43       priately before calling mkstemp().
44

CONFORMING TO

46       4.3BSD, POSIX.1-2001
47

NOTE

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

SEE ALSO

53       mkdtemp(3), mktemp(3), tempnam(3), tmpfile(3), tmpnam(3)
54
55
56
57GNU                               2001-12-23                        MKSTEMP(3)
Impressum