[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Small improvement to tmpnam()



Hi there,

here is a small patch to tmpnam.c that I created some time ago but
forgot to post then.

The file name tmpnam() creates contains a '\\' as its last path
separator. This will cause problems with programs that parse the
generated name and expect '/' to be the only valid path separator.

Now tmpnam() will check the environment variable "UNIXMODE" for the
presence of the '/' item (this indicates that the normal slash should be
used as the default path separator). The result of this check determines
whether '/' or '\\' will be used in the generated file name. Yes, it's
really simple :-)

The patch comes after my signature.

-- 
       Sascha Blank, student at the University of Trier, Germany
   private e-mail: inf03@uni-trier.de, blank@sliphost39.uni-trier.de
	     professional e-mail: ftpadmin@ftp.uni-trier.de
   PGP fingerprint: 5D EE CD 3B 36 A9 E2 AB  C1 85 4D 39 41 7E 0F 20


*** tmpnam.c.orig	Sun Sep  3 18:28:06 1995
--- tmpnam.c	Sun Sep  3 18:35:06 1995
***************
*** 1,8 ****
  /* 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)
   **/
--- 1,9 ----
  /* tmpnam.c : return a temporary file name */
  /* written by Eric R. Smith and placed in the public domain */
  /**
!  *  - usage of '/' or '\\' as path separator depends on the setting of
!  *    "UNIXMODE". This helps programs that parse the generated file name.
!  *  - returned name can be passed outside via system().
   *  - somehow more frugal in a memory use
   *    (mj - October 1990)
   **/
***************
*** 15,23 ****
  char *tmpnam(buf)
  	char *buf;
  {
! 	char *tmpdir;
  	size_t tlen;
  	extern char *mktemp __PROTO((char *));
  
  	if (((tmpdir = getenv("TEMP")) == NULL) && ((tmpdir = getenv("TMPDIR")) == NULL) &&
  	    ((tmpdir = getenv("TMP")) == NULL) && ((tmpdir = getenv("TEMPDIR")) == NULL))
--- 16,27 ----
  char *tmpnam(buf)
  	char *buf;
  {
! 	char *tmpdir, *umode;
  	size_t tlen;
  	extern char *mktemp __PROTO((char *));
+ 
+ 	if ((umode = getenv("UNIXMODE")) != NULL && strchr(umode, '/') != NULL)
+ 		pattern[0] = '/';
  
  	if (((tmpdir = getenv("TEMP")) == NULL) && ((tmpdir = getenv("TMPDIR")) == NULL) &&
  	    ((tmpdir = getenv("TMP")) == NULL) && ((tmpdir = getenv("TEMPDIR")) == NULL))