Message-Id: <3.0.1.32.19980107133235.007d35a0@yacker.xiotech.com> Date: Wed, 07 Jan 1998 13:32:35 -0600 To: djgpp-workers AT delorie DOT com From: Randy Maas Subject: patch for dup2 Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=====================_884223155==_" Precedence: bulk --=====================_884223155==_ Content-Type: text/plain; charset="us-ascii" This makes it so that a fsext can dup2() it's own file descriptor Randy --=====================_884223155==_ Content-Type: text/plain; charset="us-ascii" Content-Disposition: attachment; filename="dup2.dif" *** /local/src/libc/posix/unistd/dup2.c~1 Sun Sep 29 09:20:56 1996 --- /local/src/libc/posix/unistd/dup2.c Wed Jan 7 13:09:44 1998 *************** *** 7,10 **** --- 7,11 ---- #include #include + #include int *************** *** 12,17 **** --- 13,35 ---- { __dpmi_regs r; + __FSEXT_Function *func, *newfunc; + if (fd == newfd) return newfd; + func = __FSEXT_get_function(fd); + if (func) + { + int rv; + if (func(__FSEXT_dup2, &rv, &fd)) + return rv; + + /* We will have dup2 the fs extension's file descriptor ourselves. To + prevent trouble, we make sure that extension using newfd (if any) is + closed off. */ + newfunc = __FSEXT_get_function(newfd); + if (newfunc) + close(newfd); + } + __file_handle_set(newfd, __file_handle_modes[fd] ^ (O_BINARY|O_TEXT)); r.h.ah = 0x46; *************** *** 25,28 **** --- 43,60 ---- } setmode(newfd, __file_handle_modes[fd]); + + /* if the fd refers to a file extension, and it didn't handle the dup2() + command (eg, it is an older fsext), we can do this ourselves: just set + the handle for newfd to be the same as the handler for fd, and copy the + data part (this is a bug potential if the fsext is using a dynamically + alloced resource for the data and it does not manage this on its own) + */ + if (func) close(newfd); + { + void* data = __FSEXT_get_data(fd); + __FSEXT_set_function(newfd, func); + __FSEXT_set_data(newfd, data); + } + return newfd; } --=====================_884223155==_ Content-Type: text/plain; charset="us-ascii" --=====================_884223155==_--