www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/08/29/14:15:16

Xref: news-dnh.mv.net comp.os.msdos.djgpp:1810
Path: news-dnh.mv.net!mv!news.sprintlink.net!in2.uu.net!EU.net!i2unix!news.mclink.it!news
From: mc5686 AT mclink DOT it (Mauro Condarelli)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: tmpnam function hangs in V2
Date: Sun, 27 Aug 1995 22:32:07 GMT
Organization: MC-link The World On Line
Lines: 74
References: <DDJAID DOT 5n2 AT jade DOT mv DOT net>
Nntp-Posting-Host: 192.106.166.228
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Dj-Gateway: from newsgroup comp.os.msdos.djgpp

Marc Singer <nbn.nbn.com!sapien!elf> wrote:

>This program hangs in V2 after printing the first temporary file name.

>#include "unistd.h"
>#include "stdio.h"
>#include "stdlib.h"

>main ()
>{
>  char sz[100];

>  tmpnam (sz);
>  printf ("tmp %s\n", sz);
>  tmpnam (sz);
>  printf ("tmp %s\n", sz);
>  tmpnam (sz);
>  printf ("tmp %s\n", sz);
>  
>}  /* main */

>The first temp name is OK, but I never return from the second one.  I
>think that the code is valid because it works on Linux.

tmpnam() bug.

if your TMPDIR/TMP/TEMP doesn't have a terminating slash tmp_len gets incremented at every
call.

try this patch:
================================================
--- E:\DJGPP\SRC\LIBC\ANSI\STDIO\tmpnam.c       Sat Apr 29 01:25:56 1995
+++ tmpnam.c    Sun Aug 27 18:56:50 1995
@@ -9,7 +9,7 @@
 {
   static char static_buf[L_tmpnam];
   static char tmpcount[] = "dj000000";
-  static const char *tmp_dir=0;
+  static char *tmp_dir=0;
   static int tmp_len;
   int i;

@@ -27,13 +27,19 @@
       }
     }
     tmp_len = strlen(tmp_dir);
+    strcpy(static_buf, tmp_dir);
+    tmp_dir = static_buf;
+    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;

   if (!s)
-    s = static_buf;
-  strcpy(s, tmp_dir);
-  if (s[tmp_len - 1] != '/' && s[tmp_len - 1] != '\\' && s[tmp_len - 1] != ':')
-    s[tmp_len++] = '/', s[tmp_len] = 0;
+    s = tmp_dir;
+  else
+    strcpy(s, tmp_dir);

   do {
     /* increment the "count" starting at the first digit (backwards order) */
================================================

this should work, at least it works with yout test program :) :) :)

ciaociao

Mauro Condarelli (mc5686 AT mclink DOT it)

- Raw text -


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