File src/libc/ansi/stdio/tmpnam.c
The static variable tmp_len is initialized once when the
tmp_dir variable is retrived from environment variables.
Each time tmpnam() is called, a check is made to see if
the tmp_dir variable ends in a directory separator. If not,
tmp_len is incremented, but tmp_dir is not changed.
To solve the problem, add the directory separator to tmp_dir
inside the if(tmp_dir=0) block.
...
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 (tmp_dir[tmp_len - 1] != '/' && tmp_dir[tmp_len - 1] != '\' && tmp_dir[tmp_len - 1] != ':')
tmp_dir[tmp_len++] = '/', tmp_dir[tmp_len] = 0;
}
...