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

NAME

12       tempnam — create a name for a temporary file
13

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

55   Generating a Pathname
56       The following example generates a pathname  for  a  temporary  file  in
57       directory /tmp, with the prefix file.  After the pathname has been cre‐
58       ated, the call to free() deallocates the space used to store the  path‐
59       name.
60
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‐2017, <stdio.h>
92
94       Portions of this text are reprinted and reproduced in  electronic  form
95       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
96       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
97       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
98       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
99       event of any discrepancy between this version and the original IEEE and
100       The Open Group Standard, the original IEEE and The Open Group  Standard
101       is  the  referee document. The original Standard can be obtained online
102       at http://www.opengroup.org/unix/online.html .
103
104       Any typographical or formatting errors that appear  in  this  page  are
105       most likely to have been introduced during the conversion of the source
106       files to man page format. To report such errors,  see  https://www.ker
107       nel.org/doc/man-pages/reporting_bugs.html .
108
109
110
111IEEE/The Open Group                  2017                          TEMPNAM(3P)
Impressum