MKTEMP
Section: C Library Functions (3)
Index
Return to Main Contents
BSD mandoc
NAME
mktemp
- make temporary file name (unique)
SYNOPSIS
Fd #include <unistd.h>
Ft char *
Fn mktemp char *template
Ft int
Fn mkstemp char *template
DESCRIPTION
The
Fn mktemp
function
takes the given file name template and overwrites a portion of it
to create a file name.
This file name is unique and suitable for use
by the application.
The template may be any file name with some number of
`X'
Ns s
appended
to it, for example
/tmp/temp.XXXX
The trailing
`X'
Ns s
are replaced with the current process number and/or a
unique letter combination.
The number of unique file names
Fn mktemp
can return depends on the number of
`X'
Ns s
provided; six
`X'
Ns s
will
result in
Fn mktemp
testing roughly 26 ** 6 combinations.
The
Fn mkstemp
function
makes the same replacement to the template and creates the template file,
mode 0600, returning a file descriptor opened for reading and writing.
This avoids the race between testing for a file's existence and opening it
for use.
RETURN VALUES
The
Fn mktemp
function
returns a pointer to the template on success and
NULL
on failure.
The
Fn mkstemp
function
returns -1 if no suitable file could be created.
If either call fails an error code is placed in the global variable
errno
ERRORS
The
Fn mktemp
and
Fn mkstemp
functions
may set
errno
to one of the following values:
- Bq Er ENOTDIR
-
The pathname portion of the template is not an existing directory.
The
Fn mktemp
and
Fn mkstemp
functions
may also set
errno
to any value specified by the
stat(2)
function.
The
Fn mkstemp
function
may also set
errno
to any value specified by the
open(2)
function.
SEE ALSO
chmod(2),
getpid(2),
open(2),
stat(2)
HISTORY
A
Fn mktemp
function appeared in
AT&T System
v7 .
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- RETURN VALUES
-
- ERRORS
-
- SEE ALSO
-
- HISTORY
-
This document was created by
man2html,
using the manual pages.
Time: 15:52:54 GMT, January 15, 2023