delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/03/13/13:20:25

From: "Mark E." <snowball3 AT bigfoot DOT com>
To: djgpp-workers AT delorie DOT com
Date: Tue, 13 Mar 2001 12:50:27 -0500
MIME-Version: 1.0
Subject: exit handler for fd_props.c v2
Message-ID: <3AAE1793.22760.1821A4@localhost>
X-mailer: Pegasus Mail for Win32 (v3.12c)
Reply-To: djgpp-workers AT delorie DOT com

Here's a new patch that uses the suggestions given. Does this look ok?

Index: ansi/stdlib/exit.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdlib/exit.c,v
retrieving revision 1.5
diff -c -p -r1.5 exit.c
*** exit.c	1999/06/03 17:27:33	1.5
--- exit.c	2001/03/13 17:49:31
*************** void (*__stdio_cleanup_hook)(void);
*** 18,23 ****
--- 18,26 ----
     This does not force them to be linked in. */
  void (*__FSEXT_exit_hook)(void) = NULL;
  
+ /* A hook to close those file descriptors with properties. */
+ void (*__fd_properties_cleanup_hook)(void) = NULL;
+ 
  typedef void (*FUNC)(void);
  extern FUNC djgpp_first_dtor[] __asm__("djgpp_first_dtor");
  extern FUNC djgpp_last_dtor[] __asm__("djgpp_last_dtor");
*************** exit(int status)
*** 47,52 ****
--- 50,58 ----
       during shutdown */
    if (__stdio_cleanup_hook)
      __stdio_cleanup_hook();
+ 
+   if (__fd_properties_cleanup_hook)
+     __fd_properties_cleanup_hook();
  
    /* Do this after the stdio cleanup to let it close off the fopen'd files */
    if (__FSEXT_exit_hook)
Index: dos/io/fd_props.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/dos/io/fd_props.c,v
retrieving revision 1.1
diff -c -p -r1.1 fd_props.c
*** fd_props.c	2001/03/07 05:34:26	1.1
--- fd_props.c	2001/03/13 17:49:55
***************
*** 7,15 ****
  #include <sys/stat.h>
  #include <libc/bss.h>
  #include <fcntl.h>
! 
  #include <libc/fd_props.h>
  
  static void open_fd(fd_properties *fd, int open_flags);
  static void close_fd(fd_properties *fd);
  static fd_properties * find_eq_filename(const fd_properties *fd);
--- 7,17 ----
  #include <sys/stat.h>
  #include <libc/bss.h>
  #include <fcntl.h>
! #include <unistd.h>
  #include <libc/fd_props.h>
  
+ extern void (*__fd_properties_cleanup_hook);
+ 
  static void open_fd(fd_properties *fd, int open_flags);
  static void close_fd(fd_properties *fd);
  static fd_properties * find_eq_filename(const fd_properties *fd);
*************** static fd_properties * alloc_fd_properti
*** 17,22 ****
--- 19,25 ----
  static void free_fd_properties(fd_properties *);
  static void insert_list(fd_properties **, fd_properties *);
  static void remove_list(fd_properties **, fd_properties *);
+ static void exit_cleanup(void);
  
  /* Array of pointers to fd_properties objects associated
     with a file descriptor.  */
*************** __set_fd_properties(int fd, const char *
*** 72,77 ****
--- 75,81 ----
      if (__fd_properties == NULL)
        return -1;
      memset(__fd_properties, 0, size);
+     __fd_properties_cleanup_hook = cleanup;
    }
  
    /* This function may be called twice for the same fd,
*************** remove_list(fd_properties **head_ptr, fd
*** 210,212 ****
--- 214,236 ----
  
    *head_ptr = head;
  }
+ 
+ /* Close all known file descriptors to ensure all files marked
+    as temporary are deleted at exit.  */
+ static void
+ exit_cleanup(void)
+ {
+   int fd;
+ 
+   if (__fd_properties == NULL || active_fds == NULL)
+     return;
+ 
+   fd = 0;
+   while (fd < 255)
+   {
+     if (__fd_properties[fd])
+       close(fd);
+     ++fd;
+   }
+ }
+ 

- Raw text -


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