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
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
54       The following sections are informative.
55

EXAMPLES

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

APPLICATION USAGE

76       This function only creates pathnames. It is the application's responsi‐
77       bility to create and remove the files. Between the time a  pathname  is
78       created  and  the file is opened, it is possible for some other process
79       to create a file with the same name. Applications  may  find  tmpfile()
80       more useful.
81

RATIONALE

83       None.
84

FUTURE DIRECTIONS

86       None.
87

SEE ALSO

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