delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2004/04/23/09:28:56

X-Authentication-Warning: delorie.com: mail set sender to djgpp-workers-bounces using -f
Date: Fri, 23 Apr 2004 10:47:52 +0300 (EET DST)
From: Esa A E Peuha <peuha AT cc DOT helsinki DOT fi>
Sender: peuha AT sirppi DOT helsinki DOT fi
To: djgpp-workers AT delorie DOT com
Subject: Opening temporary files
Message-ID: <Pine.OSF.4.58.0404231046030.29213@sirppi.helsinki.fi>
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com

I noticed two things about opening temporary files that could be
improved.  The first is that a comment in tmpfile says it can't call
fdopen since it's a non-ANSI function, but this isn't a problem now that
we have the stubs thing to handle it.  The second is that popen should
set the remove-on-close flag and filename on the files it opens, so that
they will be removed even in case of abnormal exits.  popens seems to be
able to leak FILE structs under some error conditions, so I won't try to
change it before I understand exactly what it's supposed to do, but here
is a patch for tmpfile:

Index: include/libc/stubs.h
===================================================================
RCS file: /cvs/djgpp/djgpp/include/libc/stubs.h,v
retrieving revision 1.14
diff -c -r1.14 stubs.h
*** include/libc/stubs.h	6 Dec 2002 09:32:23 -0000	1.14
--- include/libc/stubs.h	22 Apr 2004 09:15:11 -0000
***************
*** 21,26 ****
--- 21,27 ----
  #define close __close
  #define dup __dup
  #define dup2 __dup2
+ #define fdopen __fdopen
  #define fnmatch __fnmatch
  #define fstatvfs __fstatvfs
  #define getcwd __getcwd
Index: src/libc/ansi/stdio/tmpfile.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/tmpfile.c,v
retrieving revision 1.4
diff -c -r1.4 tmpfile.c
*** src/libc/ansi/stdio/tmpfile.c	27 Aug 2000 15:05:54 -0000	1.4
--- src/libc/ansi/stdio/tmpfile.c	22 Apr 2004 09:15:11 -0000
***************
*** 53,70 ****
      return 0;
    }

!   /* This should have been fdopen(temp_fd, "wb+"), but `fdopen'
!      is non-ANSI.  So we need to dump some of its guts here.  Sigh...  */
!   f = __alloc_file();
    if (f)
    {
!     f->_file   = temp_fd;
!     f->_cnt    = 0;
!     f->_bufsiz = 0;
!     f->_flag   = _IORMONCL | _IORW;
      f->_name_to_remove = n_t_r;
      strcpy(f->_name_to_remove, temp_name);
-     f->_base = f->_ptr = NULL;
    }
    else
    {
--- 53,64 ----
      return 0;
    }

!   f = fdopen(temp_fd, "wb+");
    if (f)
    {
!     f->_flag |= _IORMONCL;
      f->_name_to_remove = n_t_r;
      strcpy(f->_name_to_remove, temp_name);
    }
    else
    {

-- 
Esa Peuha
student of mathematics at the University of Helsinki
http://www.helsinki.fi/~peuha/

- Raw text -


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