Mail Archives: djgpp-workers/2001/03/13/13:20:25
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 -