delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/1998/11/29/23:06:08

From: khan AT xraylith DOT wisc DOT edu (Mumit Khan)
Subject: [patch] tempnam NULL prefix handling
29 Nov 1998 23:06:08 -0800 :
Message-ID: <199811300657.AAA24419.cygnus.cygwin32.developers@modi.xraylith.wisc.edu>
To: cygwin32-developers AT cygnus DOT com

See bug report in gnu-win32 list for details. Wish someone would volunteer
(obviously not me ;-) to clean up the newlib prototypes for ANSI
conformance (mostly 'const char*' instead of 'char*') and fix the rest
of the bugs in str* routines while at it.

The fix doesn't fix the problem fully (see SVID/BSD tempnam for the
"up to 5 characters of prefix"), but since POSIX code shouldn't be using
it anyway, I don't care to do any more.

Mon Nov 30 01:22:25 1998  Mumit Khan  <khan AT xraylith DOT wisc DOT edu>

	* libc/include/stdio.h (tempnam): Add prototype.
	* libc/stdio/tmpnam.c (_tempnam_r): Handle NULL prefix.

--- libc/include/stdio.h.~1	Mon Nov 30 01:24:09 1998
+++ libc/include/stdio.h	Mon Nov 30 01:25:01 1998
@@ -128,6 +128,7 @@ typedef struct __sFILE FILE;
 int	_EXFUN(remove, (const char *));
 int	_EXFUN(rename, (const char *, const char *));
 #endif
+char *	_EXFUN(tempnam, (const char *, const char *));
 FILE *	_EXFUN(tmpfile, (void));
 char *	_EXFUN(tmpnam, (char *));
 int	_EXFUN(fclose, (FILE *));

--- libc/stdio/tmpnam.c.~1	Mon Nov 30 01:17:12 1998
+++ libc/stdio/tmpnam.c	Mon Nov 30 01:19:03 1998
@@ -171,16 +171,17 @@ _DEFUN (_tempnam_r, (p, dir, pfx),
 {
   char *filename;
   int length;
+  _CONST char *prefix = (pfx) ? pfx : "";
   if (dir == NULL && (dir = getenv ("TMPDIR")) == NULL)
     dir = P_tmpdir;
 
   /* two 8 digit numbers + . / */
-  length = strlen (dir) + strlen (pfx) + (4 * sizeof (int)) + 2 + 1;
+  length = strlen (dir) + strlen (prefix) + (4 * sizeof (int)) + 2 + 1;
 
   filename = _malloc_r (p, length);
   if (filename)
     {
-      if (! worker (p, filename, dir, pfx,
+      if (! worker (p, filename, dir, prefix,
 		    _getpid_r (p) ^ (int) (_POINTER_INT) p, &p->_inc))
 	return NULL;
     }

Regards,
Mumit

- Raw text -


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