www.delorie.com/djgpp/doc/libc/libc_815.html   search  
libc.a reference

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]



#include <stdio.h>

char * tempnam(const char *tmpdir, const char *prefix);


This function generates a file name which can be used for a temporary file, and makes sure that no other file by that name exists.

The caller has control on the choice of the temporary file's directory, and the initial letters of the file's basename. If the argument tmpdir points to the name of the directory in which the temporary file will be created, tempnam will ensure that the generate name is unique in that directory. If the argument prefix points to a string, then that string will be used as the first few characters of the file's basename. Due to limitations of the DOS 8.3 file namespace, only up to two first characters in prefix will be used.

If tmpdir is NULL, or empty, or points to a non-existent directory, tempnam will use a default directory. The default directory is determined by testing, in sequence, the directories defined by the values of environment variables TMPDIR, TEMP and TMP. The first variable that is found to point to an existing directory will be used. If none of these variables specify a valid directory, tempnam will use the static default path prefix defined by P_tmpdir on `<stdio.h>', or "c:/", in that order.

If prefix is NULL or empty, tempnam will supply its own default prefix "tm".

tempnam puts the generated name into space allocated by malloc. It is up to the caller to free that space when it is no longer needed.

Note that tempnam does not actually create the file, nor does it ensure in any way that the file will be automatically deleted when it's no longer used. It is the user's responsibility to do that.

Return Value

On success, tempnam returns a pointer to space (allocated with a call to malloc) where the file name is constructed. If malloc failed to provide sufficient memory buffer, or if no valid directory to hold the file was found, tempnam returns a NULL pointer.




  #include <stdio.h>

    tempnam ("c:/tmp/", "foo");

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright © 2004     Updated Apr 2004