tempnam() generates a pathname that may be used for a temporary file.
tempnam() allows the user to control the choice of a directory.
dir points to the name of the directory in which the file is to be created. If the environment variable TMPDIR is set, the directory specified there is used; otherwise, the one named under *dir. If dir is a null pointer and the directory {P_tmpdir} does not name an accessible directory, the file names are generated with the directory name /tmp . If this is not accessible either, 0 is returned. P_tmpdir is defined in stdio.h as "/var/tmp" as the directory in which temporary files are created.
Many applications prefer their temporary files to have specific initial letter sequences in their names. The pfx argument should be used for this. This argument may be a null pointer or point to a string of up to five bytes to be used as the first bytes in the name of the temporary file. The name component generated by tempnam() is made up of two parts: the first comprises three uppercase letters (AAA, BAA, ..., ZAA, ZBA, ..., ZZZ); the second consists of a letter and the last five characters of the process ID. If the process ID consists of less than five characters, it is padded to five characters with leading zeros. For example, a complete name produced would be: /var/tmp/AAAa00123. tempnam() uses malloc() to obtain space for the generated file name and returns a pointer to that area. Thus, any pointer value returned by tempnam() can serve as an argument to free() (see malloc() ). If tempnam() cannot return the expected result for some reason, e.g. because malloc() failed or no appropriate directory could be found, a null pointer is returned.
tempnam() will fail if not enough memory is available.
|