www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000016

When Created: 08/15/1995 04:16:52
Against DJGPP version: 2.00.beta2
By whom: Peter.Olausson@sth.frontec.se
Abstract: tmpnam() fails second time if %DJGPP% ends without / or \
The tmpnam() function in libc.a(stdio) runs into an infinite loop
the second time it is called. The problem will occur only if
thje environment variable DJGPP or TEMP ends without a trailing
directory separator.

Solution added: 08/15/1995 04:26:37
By whom: Peter.Olausson@sth.frontec.se
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;
  }
...

Fixed in version 2.00.beta3 on 08/22/1995 21:27:44
By whom: dj@delorie.com



  webmaster     delorie software   privacy  
  Copyright © 2010   by DJ Delorie     Updated Jul 2010