From: Marc Singer Subject: Patch for tmpnam() (v2) To: nbn.nbn.com!sapien!sun.soe.clarkson.edu!djgpp (DJGPP List Alias) Date: Sun, 20 Aug 1995 16:14:37 -0700 (PDT) Ok. It isn;t really a `patch'. Here is a version of tmpname() that does not bomb if $TMP doesn't end with a path separator. -------------------- cut -------------------- char * tmpnam(char *s) { static char static_buf[L_tmpnam]; static char tmpcount[] = "dj000000"; static const char *tmp_dir=0; static int tmp_len; int i; char* pchCount; if (tmp_dir == 0) { tmp_dir = getenv("TMPDIR"); if (!tmp_dir || access(tmp_dir, D_OK)) { tmp_dir = getenv("TEMP"); if (!tmp_dir || access(tmp_dir, D_OK)) { tmp_dir = getenv("TMP"); if (!tmp_dir || access(tmp_dir, D_OK)) tmp_dir = "c:/"; } } tmp_len = strlen(tmp_dir); } if (!s) s = static_buf; strcpy(s, tmp_dir); pchCount = s + tmp_len; if (s[tmp_len - 1] != '/' && s[tmp_len - 1] != '\\' && s[tmp_len - 1] != ':') s[tmp_len] = '/', ++pchCount, s[tmp_len + 1] = 0; do { /* increment the "count" starting at the first digit (backwards order) */ for (i=2; tmpcount[i] == '9' && i < 8; tmpcount[i] = '0', i++); if (i < 8) tmpcount[i]++; strcpy(pchCount, tmpcount); } while (access (s, F_OK) == 0); /* until file doesn't exist */ return s; } -------------------- cut -------------------- ---------------------------------------------------------------------- Marc Singer | "... but when you eat this ... pear, you elf AT netcom DOT com | are rarely aware of the fact that it was or elf AT sapien DOT com | ... plucked from the branch of this ... < My comments are my own. > | pear tree." -- Charlie V.