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

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



#include <stdio.h>

char *tmpnam(char *s);


This function generates a string that is a valid file name and that is not the same as the name of an existing file. A different string is guaranteed to be produced each time it is called, up to TMP_MAX times (TMP_MAX is defined on stdio.h). If tmpnam is called more than TMP_MAX times, the behavior is implementation-dependent (ours just wraps around and tries to reuse the same file names from the beginning).

This function examines the environment to determine the directory in which the temporary file will be opened. It looks for one of the variables "TMPDIR", "TEMP" and "TMP", in that order. The first one which is found in the environment will be used on the assumption that it points to a directory. If neither of the above variables is defined, tmpnam defaults to the "c:/" directory (which under MS-DOS might mean that it fails to generate TMP_MAX unique names, because DOS root directories cannot grow beyond certain limits).

Return Value

If s is a null pointer, tmpnam leaves its result in an internal static buffer and returns a pointer to that buffer. If s is not a null pointer, it is assumed to point to an array of at least L_tmpnam characters, and tmpnam writes its result in that array and returns a pointer to it as its value.


POSIX 1003.2-1992; 1003.1-2001


char buf[L_tmpnam];
char *s = tmpnam(buf);

  webmaster     delorie software   privacy  
  Copyright © 2004     Updated Apr 2004