1TEMPNAM(P)                 POSIX Programmer's Manual                TEMPNAM(P)
2
3
4

NAME

6       tempnam - create a name for a temporary file
7

SYNOPSIS

9       #include <stdio.h>
10
11       char *tempnam(const char *dir, const char *pfx);
12
13

DESCRIPTION

15       The tempnam() function shall generate a pathname that may be used for a
16       temporary file.
17
18       The tempnam() function allows the user  to  control  the  choice  of  a
19       directory.  The  dir  argument  points  to the name of the directory in
20       which the file is to be created. If dir is a null pointer or points  to
21       a  string  which  is  not a name for an appropriate directory, the path
22       prefix defined as P_tmpdir in the <stdio.h> header shall  be  used.  If
23       that  directory  is not accessible, an implementation-defined directory
24       may be used.
25
26       Many applications prefer their temporary files to have certain  initial
27       letter  sequences  in  their names. The pfx argument should be used for
28       this. This argument may be a null pointer or point to a string of up to
29       five bytes to be used as the beginning of the filename.
30
31       Some implementations of tempnam() may use tmpnam() internally.  On such
32       implementations, if called  more  than  {TMP_MAX}  times  in  a  single
33       process, the behavior is implementation-defined.
34

RETURN VALUE

36       Upon  successful  completion,  tempnam()  shall  allocate  space  for a
37       string, put the generated pathname in that space, and return a  pointer
38       to  it.  The  pointer shall be suitable for use in a subsequent call to
39       free(). Otherwise, it shall return a null  pointer  and  set  errno  to
40       indicate the error.
41

ERRORS

43       The tempnam() function shall fail if:
44
45       ENOMEM Insufficient storage space is available.
46
47
48       The following sections are informative.
49

EXAMPLES

51   Generating a Pathname
52       The  following  example  generates  a  pathname for a temporary file in
53       directory /tmp, with the prefix file. After the filename has been  cre‐
54       ated,  the call to free() deallocates the space used to store the file‐
55       name.
56
57
58              #include <stdio.h>
59              #include <stdlib.h>
60              ...
61              char *directory = "/tmp";
62              char *fileprefix = "file";
63              char *file;
64
65
66              file = tempnam(directory, fileprefix);
67              free(file);
68

APPLICATION USAGE

70       This function only creates pathnames. It is the application's responsi‐
71       bility  to  create and remove the files. Between the time a pathname is
72       created and the file is opened, it is possible for some  other  process
73       to  create  a  file with the same name. Applications may find tmpfile()
74       more useful.
75

RATIONALE

77       None.
78

FUTURE DIRECTIONS

80       None.
81

SEE ALSO

83       fopen() , free() , open() , tmpfile() , tmpnam() , unlink() , the  Base
84       Definitions volume of IEEE Std 1003.1-2001, <stdio.h>
85
87       Portions  of  this text are reprinted and reproduced in electronic form
88       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
89       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
90       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
91       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
92       event of any discrepancy between this version and the original IEEE and
93       The  Open Group Standard, the original IEEE and The Open Group Standard
94       is the referee document. The original Standard can be  obtained  online
95       at http://www.opengroup.org/unix/online.html .
96
97
98
99IEEE/The Open Group                  2003                           TEMPNAM(P)
Impressum