www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/04/08:25:41

Message-Id: <l03130300b496614bbdcf@[145.98.119.193]>
Mime-Version: 1.0
Date: Mon, 3 Jan 2000 15:39:29 +0100
To: djgpp AT delorie DOT com
From: Dlanor Blytkerchan <dlanor AT dds DOT nl>
Subject: a bug?
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id HAA04688
Reply-To: djgpp AT delorie DOT com

The following two pieces of code reveal what I believe to be a bug in tmpfile():

: #include <stdio.h>
: 
: int main(void) {
:   int i;
:   FILE *CC;
: 
:   for (i = 0; i < TMP_MAX; i++) {
:     printf("%d: %p\n", i, (CC = fopen(tmpnam(0), "ab")));
:     if (!CC) getch();
:   } // for
: } // main()
displays (on my computer) 23 pointers and subsequently zeros, stopping after each zero (seems right)

: #include <stdio.h>
: 
: int main(void) {
:   int i;
: 
:   for (i = 0; i < TMP_MAX; i++) printf("%d: %p\n", tmpfile());
: } // main()
displays (on my computer) 23 pointers and subsequently hangs.

I've looked this method up in the GCC source code distributed with Red Hat Linux to compare with the DJGPP code: according to that code, tmpfile() should return NULL if it can't create the file or make a unique filename - which is what I would expect of such a function.
My computer - by the way - is a pentium III at 450 MHz, with a 15 GB hard drive and produces the same results no matter what the TMPFILE environment variable is - which in the test cases were set by subsequent runs of RHIDE, and by me (when not trying it in RHIDE).
In the Sally full screen debugger, I've found tmpnam() works, tmpfile() starts looping eternally immediatly after tmpnam() is called and a register is tested, calling tmpnam() again. As I do not have the source code of the DJGPP implementation of gcc, I assume there is some while or for loop involved, which becomes eternal. (Luckily, Ctrl-C works).

Hopefully, I have provided enough info for someone to either fix the problem, or tell me what I'm doing wrong in expecting tmpfile() to return NULL if it can't open another file.. (NB: the cause of not being able to open the file is probably with the FILES environment variable, which I will test after having written this..).

Greetz!

Dlanor

NB: As I'm not a subscriber to this maillist, please respond directly to me as well as to the list & forgive me if I should have sent this somewhere else - I couldn't find an appropriate E-mail address in the readme.


- Raw text -


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