1tmpnam(3C)               Standard C Library Functions               tmpnam(3C)
2
3
4

NAME

6       tmpnam, tmpnam_r, tempnam - create a name for a temporary file
7

SYNOPSIS

9       #include <stdio.h>
10
11       char *tmpnam(char *s);
12
13
14       char *tmpnam_r(char *s);
15
16
17       char *tempnam(const char *dir, const char *pfx);
18
19

DESCRIPTION

21       These  functions generate file names that can be used safely for a tem‐
22       porary file.
23
24   tmpnam()
25       The tmpnam() function always generates a file name using the path  pre‐
26       fix  defined  as  P_tmpdir in the <stdio.h> header. On Solaris systems,
27       the default value for P_tmpdir is  /var/tmp. If  s  is  NULL,  tmpnam()
28       leaves  its result in a thread-specific data area and returns a pointer
29       to that area. The next call to tmpnam() by the same thread will destroy
30       the  contents  of  the  area. If s is not NULL, it is assumed to be the
31       address of an array of at least L_tmpnam bytes,  where  L_tmpnam  is  a
32       constant defined through inclusion of <stdio.h>. The  tmpnam() function
33       places its result in that array and returns s.
34
35   tmpnam_r()
36       The tmpnam_r() function has the same functionality as  tmpnam()  except
37       that if s is a null pointer, the function returns NULL.
38
39   tempnam()
40       The  tempnam()  function  allows  the  user  to control the choice of a
41       directory. The argument dir points to the  name  of  the  directory  in
42       which  the  file is to be created. If dir is NULL or points to a string
43       that is not a name  for  an  appropriate  directory,  the  path  prefix
44       defined  as P_tmpdir in the <stdio.h> header is used. If that directory
45       is not accessible, /tmp is used. If, however,  the  TMPDIR  environment
46       variable  is  set  in  the user's environment, its value is used as the
47       temporary-file directory.
48
49
50       Many applications prefer that  temporary  files  have  certain  initial
51       character  sequences  in  their  names. The pfx argument may be NULL or
52       point to a string of up to five characters to be used  as  the  initial
53       characters of the temporary-file name.
54
55
56       Upon successful completion, tempnam() uses malloc(3C) to allocate space
57       for a string, puts the generated pathname in that space, and returns  a
58       pointer  to it. The pointer is suitable for use in a subsequent call to
59       free(). If tempnam() cannot return the expected result for  any  reason
60       (for  example,  malloc()  failed),  or  if  none of the above-mentioned
61       attempts to find  an  appropriate  directory  was  successful,  a  null
62       pointer is returned and errno is set to indicate the error.
63

ERRORS

65       The tempnam() function will fail if:
66
67       ENOMEM    Insufficient storage space is available.
68
69

USAGE

71       These  functions  generate  a  different  file  name each time they are
72       called.
73
74
75       Files created using these functions and either  fopen(3C)  or  creat(2)
76       are  temporary  only  in  the  sense  that  they  reside in a directory
77       intended for temporary use, and their  names  are  unique.  It  is  the
78       user's responsibility to remove the file when its use is ended.
79
80
81       If  called  more  than TMP_MAX (defined in <stdio.h>) times in a single
82       process, these functions start recycling previously used names.
83
84
85       Between the time a file name is created and the file is opened,  it  is
86       possible  for  some  other process to create a file with the same name.
87       This can never happen if that other process is using these functions or
88       mktemp(3C) and the file names are chosen to render duplication by other
89       means unlikely.
90
91
92       The tmpnam() function is safe  to  use  in  multithreaded  applications
93       because it employs thread-specific data if it is passed a NULL pointer.
94       However, its use is discouraged. The tempnam() function is safe in mul‐
95       tithreaded applications and should be used instead.
96
97
98       When compiling multithreaded applications, the  _REENTRANT flag must be
99       defined on the compile line.  This flag should be used only with multi‐
100       threaded applications.
101

ATTRIBUTES

103       See attributes(5) for descriptions of the following attributes:
104
105
106
107
108       ┌─────────────────────────────┬─────────────────────────────────────┐
109       │      ATTRIBUTE TYPE         │          ATTRIBUTE VALUE            │
110       ├─────────────────────────────┼─────────────────────────────────────┤
111       │Interface Stability          │tmpnam() and tempnam() are Standard. │
112       ├─────────────────────────────┼─────────────────────────────────────┤
113       │MT-Level                     │Safe                                 │
114       └─────────────────────────────┴─────────────────────────────────────┘
115

SEE ALSO

117       creat(2),   unlink(2),  fopen(3C),  free(3C),  malloc(3C),  mktemp(3C),
118       mkstemp(3C), tmpfile(3C), attributes(5), standards(5)
119
120
121
122SunOS 5.11                        18 May 2004                       tmpnam(3C)
Impressum