Date: Wed, 30 Aug 2000 02:48:07 +0900 (JST) From: Tatsuya Kudoh <cdr@cosmonet.org> To: FreeBSD-gnats-submit@freebsd.org Subject: i386/20925: doscmd(1) does not truncate a file Message-ID: <200008291744.CAA02429@planar.cosmonet.org>
next in thread | raw e-mail | index | archive | help
>Number: 20925 >Category: i386 >Synopsis: doscmd(1) does not truncate a file int write functio-call. >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Aug 29 11:00:01 PDT 2000 >Closed-Date: >Last-Modified: >Originator: Tatsuya Kudoh >Release: FreeBSD 3.5-RELEASE i386 >Organization: >Environment: FreeBSD 3.2 or later kernel compiled with 'options "VM86"' >Description: Under MS-DOS, the write function-call with size parameter is 0, it means file truncating. This function is not implemented in doscmd(1). >How-To-Repeat: Some MS-DOS applications. In my environment, LSI Japans's LSI C-86 C compiler does not work. >Fix: This is a patch for dsmcd(1) on 3.5-RELEASE ------------------------------------------- *** dos.c.old Sat Aug 12 22:36:06 2000 --- dos.c Sat Aug 12 22:42:08 2000 *************** *** 1308,1313 **** --- 1308,1329 ---- ** write */ static int + write_or_truncate(int fd, char *addr, int len) + { + off_t offset; + + if ( len == 0 ){ + offset = lseek(fd,0,SEEK_CUR); + if( offset < 0 ) + return -1; + else + return ftruncate(fd,offset); + } else { + return write(fd,addr,len); + } + } + + static int int21_40(regcontext_t *REGS) { char *addr; *************** *** 1321,1327 **** switch (R_BX) { case 0: if (redirect0) { ! n = write (R_BX, addr, nbytes); break; } n = nbytes; --- 1337,1343 ---- switch (R_BX) { case 0: if (redirect0) { ! n = write_or_truncate (R_BX, addr, nbytes); break; } n = nbytes; *************** *** 1330,1336 **** break; case 1: if (redirect1) { ! n = write (R_BX, addr, nbytes); break; } n = nbytes; --- 1346,1352 ---- break; case 1: if (redirect1) { ! n = write_or_truncate (R_BX, addr, nbytes); break; } n = nbytes; *************** *** 1339,1345 **** break; case 2: if (redirect2) { ! n = write (R_BX, addr, nbytes); break; } n = nbytes; --- 1355,1361 ---- break; case 2: if (redirect2) { ! n = write_or_truncate (R_BX, addr, nbytes); break; } n = nbytes; *************** *** 1347,1353 **** tty_write(*addr++, -1); break; default: ! n = write (R_BX, addr, nbytes); break; } if (n < 0) --- 1363,1369 ---- tty_write(*addr++, -1); break; default: ! n = write_or_truncate (R_BX, addr, nbytes); break; } if (n < 0) >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200008291744.CAA02429>