![]() Chapter Contents |
![]() Previous |
![]() Next |
| tmpnam |
| Portability: | ISO/ANSI C conforming, UNIX compatible |
| SYNOPSIS | |
| DESCRIPTION | |
| RETURN VALUE | |
| CAUTION | |
| IMPLEMENTATION | |
| EXAMPLE | |
| RELATED FUNCTIONS | |
| SEE ALSO |
| SYNOPSIS |
#include <stdio.h> char *tmpnam(char *buf);
| DESCRIPTION |
tmpnam
generates a string that is a valid filename and is not the same as the name
of any existing file. If a file with this name is opened, it continues to
exist after program termination.
tmpnam
generates up to
TMP_MAX
filenames, a different
name each time it is called.
For a program compiled with the
posix
option, the name returned by
tmpnam
defines a file in the HFS directory
/tmp
.
| RETURN VALUE |
If
buf
is
NULL
,
tmpnam
leaves its result in an internal static object and returns a pointer
to that object. Subsequent calls to
tmpnam
may modify that same object.
If
buf
is not
NULL
, it is assumed to point to an array of at
least
L_tmpnam
characters;
tmpnam
writes its result in that array and returns the argument as
its value.
| CAUTION |
The generated filenames are designed to
be unique. The library makes 100 attempts to generate a unique filename at
each call to
tmpnam
. If after 100 attempts
it cannot generate a unique filename,
tmpnam
returns
NULL
.
| IMPLEMENTATION |
This implementation essentially assigns
a value of infinity to
TMP_MAX
because
it is virtually impossible to cause an error by calling
tmpnam
too many times.
The returned filename strings are composed as follows:
dsn:userid.jobid. $ddmonyr.$hhmmss. $tens-of-microseconds
dsn:GEORGE.JOB01234.$10NOV88.$142253.$0000792
If a userid is not available, use
"C-TMP"
. Here is an example:
dsn:C-TMP.JOB01234.$10NOV88.$142253.$0000792
cms:$ddmonyr $tens-of-microseconds fml
cms:$10NOV88 $0000792 A1
The CMS filemode letter is chosen from the read and write disk with the most space.
/tmp/logonid.pid.ddmonyr.hhmmss.tens-of-microseconds
/tmp/JANE.524290.10NOV94.142253.0000792
| EXAMPLE |
#include <stdio.h>
#include <stdlib.h>
main()
{
char *name;
FILE *temp;
name = tmpnam(NULL);
if (name == NULL) exit(EXIT_FAILURE);
temp = fopen(name, "w");
fputs("Hello, temporary world.\n", temp);
fclose(temp);
remove(name);
}
| RELATED FUNCTIONS |
| SEE ALSO |
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.