/* tmpnam.c : return a temporary file name */ /* written by Eric R. Smith and placed in the public domain */ /** * - retuned name can be passed outside via system(); other programs * may not dig '/' as a path separator * - somehow more frugal in a memory use * (mj - October 1990) **/ #include #include #include static char pattern[] = "\\__XXXXXX"; char *tmpnam(buf) char *buf; { char *tmpdir; extern char *mktemp __PROTO((char *)); if (!(tmpdir = getenv("TEMP")) && !(tmpdir = getenv("TMPDIR"))) tmpdir = "."; if (!buf) { size_t blen; blen = strlen (tmpdir) + sizeof(pattern); if (NULL == (buf = malloc(blen))) return NULL; } (void) strcat(strcpy(buf, tmpdir), pattern); return(mktemp(buf)); }