delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/02/11:43:09

From: G DOT Boggio AT agora DOT stm DOT it
Message-Id: <199804021639.SAA25512@agora.stm.it>
To: djgpp AT delorie DOT com
Date: Thu, 2 Apr 98 18:39:23 ITA
Subject: tmpfile() creates a text file

I do not usually read the list, so I do not know whether the problem
has already been reported.  If it has, I apologize for the duplication.

tmpfile() apparently creates a text file.  I do not have the ANSI
Standard, but, according to K&R 2nd ed., the mode should be "wb+".

This program:

 #include <stdio.h>
 main ()
 {
        FILE	*f ;
        char	record [1000] ;
        int	n ;
        for (n=0;n<1000;n++)
                record [n] = 'a' ;
 /*     record [500] = 26 ;      */
        f = tmpfile() ;
        fwrite (record, 1, 1000, f) ;
        fflush (f) ;
        rewind (f) ;
        n = fread (record, 1, 1000, f) ;
        printf ("%d\n", n) ;
 }

when compiled and linked with DJGPP 2.01, prints 1000. If the instruction
is uncommented, it prints 500.

The problem is easily bypassed by using tmpnam() and remove().

--
  Gianfranco Boggio
  Milano (Italy)

- Raw text -


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