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

When Created: 10/02/1997 17:45:47
Against DJGPP version: 2.01
By whom: Wolfgang.Glunz@mchp.siemens.de
Abstract: tempname does not return a pointer to new memory
Under all systems I known, tempnam returns a pointer to newly allocated memory if
the first parameter is 0. Under djgpp 2.01 tempnam behaves the same as tmpnam 
which returns a pointer to a static memory which is overwritten after each call
to tmpnam.

The following program illustrates the bug;

#include <iostream.h>
#include <stdio.h>
 
int main()
{
 char * p1 = tempnam(0,"t1");
 char * p2 = tempnam(0,"t2");
 cout << p1 << " " << p2 << endl;
};
 

Normally one gets two different values whereas under
djgpp 2.01 p1 and p2 are the same.

I also looked at the sources and found:
char *
tempnam(const char *_dir, const char *_prefix)
{
  return tmpnam(0);
}

A correct approximation based on tmpnam would be
  return strdup(tmpnam(0));

Solution added: 10/02/1997 17:49:46
By whom: Wolfgang.Glunz@mchp.siemens.de
use
     return strdup(tmpnam(0)); 
instead of
     return tmpnam(0);

Fixed in version on 04/12/1999 11:00:27
By whom: eliz@is.elta.co.il



  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2010   by DJ Delorie     Updated Jul 2010