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

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       tempnam — create a name for a temporary file
14

SYNOPSIS

16       #include <stdio.h>
17
18       char *tempnam(const char *dir, const char *pfx);
19

DESCRIPTION

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

RETURN VALUE

42       Upon successful  completion,  tempnam()  shall  allocate  space  for  a
43       string,  put the generated pathname in that space, and return a pointer
44       to it. The pointer shall be suitable for use in a  subsequent  call  to
45       free().   Otherwise,  it  shall  return a null pointer and set errno to
46       indicate the error.
47

ERRORS

49       The tempnam() function shall fail if:
50
51       ENOMEM Insufficient storage space is available.
52
53       The following sections are informative.
54

EXAMPLES

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

APPLICATION USAGE

73       This function only creates pathnames. It is the application's responsi‐
74       bility to create and remove the files. Between the time a  pathname  is
75       created  and  the file is opened, it is possible for some other process
76       to create a file with the same name. Applications  may  find  tmpfile()
77       more useful.
78
79       Applications  should  use  the tmpfile(), mkdtemp(), or mkstemp() func‐
80       tions instead of the obsolescent tempnam() function.
81

RATIONALE

83       None.
84

FUTURE DIRECTIONS

86       The tempnam() function may be removed in a future version.
87

SEE ALSO

89       fopen(), free(), mkdtemp(), open(), tmpfile(), tmpnam(), unlink()
90
91       The Base Definitions volume of POSIX.1‐2008, <stdio.h>
92
94       Portions of this text are reprinted and reproduced in  electronic  form
95       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
96       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
97       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
98       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
99       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
100       event of any discrepancy between this version and the original IEEE and
101       The  Open Group Standard, the original IEEE and The Open Group Standard
102       is the referee document. The original Standard can be  obtained  online
103       at http://www.unix.org/online.html .
104
105       Any  typographical  or  formatting  errors that appear in this page are
106       most likely to have been introduced during the conversion of the source
107       files  to  man page format. To report such errors, see https://www.ker
108       nel.org/doc/man-pages/reporting_bugs.html .
109
110
111
112IEEE/The Open Group                  2013                          TEMPNAM(3P)
Impressum