tmpnam -- Generate Temporary Filename

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:

MVS

 dsn:u serid.jobid. $ ddmonyr.$ hhmmss. $ tens-of-microseconds
 
Here is an example:
 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
 cms:$ ddmonyr  $ tens-of-microseconds fml
 
Here is an example:
 cms:$10NOV88 $0000792 A1
 

The CMS filemode letter is chosen from the read and write disk with the most space.

OpenEdition

 /tmp/logonid.pid.ddmonyr.hhmmss.tens-of-microseconds
 

For example:

 /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

tmpfile

SEE ALSO


Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.