Message-Id: <199904252128.VAA51774@out4.ibm.net> From: "Mark E." To: djgpp-workers AT delorie DOT com Date: Sun, 25 Apr 1999 17:29:32 -0400 MIME-Version: 1.0 Content-type: Multipart/Mixed; boundary=Message-Boundary-11044 Subject: Re: fsext patches for dup and dup2 X-mailer: Pegasus Mail for Win32 (v3.01d) Reply-To: djgpp-workers AT delorie DOT com --Message-Boundary-11044 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Mail message body > True, it won't work for fsext allocated handles. But when fsext is used to > keep state information about a actual handle (e.g. for emulating the > pipes), then adding fsext code to dup & dup2 is essential for the > emulation to work properly... Since the only good use of adding fsext code to dup{2} is to let the fsext handler update state information, then they should be modified to provide it after getting the new handle, rather than make the fsext handler get the value itself by yet another call to dup{2}. See the attached patch for my revised patch. Mark --- Mark Elbrecht, snowball3 AT usa DOT net http://snowball.frogspace.net/ --Message-Boundary-11044 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Content-description: Text from file 'dup.dif' Index: djgpp/src/libc/posix/unistd/dup.c =================================================================== RCS file: /cvs/djgpp/djgpp/src/libc/posix/unistd/dup.c,v retrieving revision 1.1 diff -c -3 -r1.1 dup.c *** dup.c 1995/02/27 00:43:08 1.1 --- dup.c 1999/04/25 21:21:28 *************** *** 5,15 **** --- 5,18 ---- #include #include #include + #include int dup(int fd) { __dpmi_regs r; + __FSEXT_Function *func; + r.h.ah = 0x45; r.x.bx = fd; __dpmi_int(0x21, &r); *************** *** 18,23 **** --- 21,41 ---- errno = __doserr_to_errno(r.x.ax); return -1; } + + /* Give a FSEXT handler a chance to update the state data + associated with the two handles. */ + func = __FSEXT_get_function(fd); + if (func) + { + int rv; + int fds[2]; + fds[0] = fd; + fds[1] = r.x.ax; + /* Indicate __FSEXT_dup2 since we already have the duplicated handle. */ + if (func(__FSEXT_dup2, &rv, fds)) + return rv; + } + setmode(r.x.ax, __file_handle_modes[fd]); return r.x.ax; } Index: djgpp/src/libc/posix/unistd/dup.c =================================================================== RCS file: /cvs/djgpp/djgpp/src/libc/posix/unistd/dup.c,v retrieving revision 1.1 diff -c -3 -r1.1 dup.c *** dup.c 1995/02/27 00:43:08 1.1 --- dup.c 1999/04/25 21:21:38 *************** *** 5,15 **** --- 5,18 ---- #include #include #include + #include int dup(int fd) { __dpmi_regs r; + __FSEXT_Function *func; + r.h.ah = 0x45; r.x.bx = fd; __dpmi_int(0x21, &r); *************** *** 18,23 **** --- 21,41 ---- errno = __doserr_to_errno(r.x.ax); return -1; } + + /* Give a FSEXT handler a chance to update the state data + associated with the two handles. */ + func = __FSEXT_get_function(fd); + if (func) + { + int rv; + int fds[2]; + fds[0] = fd; + fds[1] = r.x.ax; + /* Indicate __FSEXT_dup2 since we already have the duplicated handle. */ + if (func(__FSEXT_dup2, &rv, fds)) + return rv; + } + setmode(r.x.ax, __file_handle_modes[fd]); return r.x.ax; } --Message-Boundary-11044--