Mail Archives: djgpp-workers/2001/08/12/12:37:46
dup and dup2 don't copy the FSEXT hooks. Thus, if you do the usual
redirection dance (dup, close, dup2), you lose the FSEXT hook forever.
The changes below fix that. Comments?
Index: src/libc/posix/unistd/dup.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/unistd/dup.c,v
retrieving revision 1.2
diff -u -p -r1.2 dup.c
--- src/libc/posix/unistd/dup.c 2001/03/07 05:40:26 1.2
+++ src/libc/posix/unistd/dup.c 2001/08/12 16:31:32
@@ -5,6 +5,7 @@
#include <dpmi.h>
#include <errno.h>
#include <io.h>
+#include <sys/fsext.h>
#include <libc/dosio.h>
#include <libc/fd_props.h>
@@ -20,8 +21,10 @@ dup(int fd)
errno = __doserr_to_errno(r.x.ax);
return -1;
}
- setmode(r.x.ax, __file_handle_modes[fd]);
+ /* Copy the fsext hook, the handle modes, and the properties. */
+ __FSEXT_set_function(r.x.ax, __FSEXT_get_function(fd));
+ setmode(r.x.ax, __file_handle_modes[fd]);
if (__has_fd_properties(fd))
__dup_fd_properties(fd, r.x.ax);
Index: src/libc/posix/unistd/dup2.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/unistd/dup2.c,v
retrieving revision 1.4
diff -u -p -r1.4 dup2.c
--- src/libc/posix/unistd/dup2.c 2001/03/07 05:40:27 1.4
+++ src/libc/posix/unistd/dup2.c 2001/08/12 16:31:46
@@ -7,6 +7,7 @@
#include <dpmi.h>
#include <errno.h>
#include <io.h>
+#include <sys/fsext.h>
#include <libc/dosio.h>
#include <libc/fd_props.h>
@@ -16,7 +17,12 @@ dup2(int fd, int newfd)
__dpmi_regs r;
if (fd == newfd)
return newfd;
+ /* Reset the text/binary modes, the fsext, and the properties, since
+ DOS function 46h closes newfd. */
__file_handle_set(newfd, __file_handle_modes[fd] ^ (O_BINARY|O_TEXT));
+ __FSEXT_set_function(newfd, 0);
+ if (__has_fd_properties(newfd))
+ __clear_fd_properties(newfd);
r.h.ah = 0x46;
r.x.bx = fd;
r.x.cx = newfd;
@@ -26,10 +32,10 @@ dup2(int fd, int newfd)
errno = __doserr_to_errno(r.x.ax);
return -1;
}
- setmode(newfd, __file_handle_modes[fd]);
- if (__has_fd_properties(newfd))
- __clear_fd_properties(newfd);
+ /* Copy the fsext hook, the handle modes, and the properties. */
+ __FSEXT_set_function(newfd, __FSEXT_get_function(fd));
+ setmode(newfd, __file_handle_modes[fd]);
if (__has_fd_properties(fd))
__dup_fd_properties(fd, newfd);
- Raw text -