From owner-freebsd-bugs Tue Aug 29 11: 0:11 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id CC8E537B423 for ; Tue, 29 Aug 2000 11:00:01 -0700 (PDT) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id LAA90701; Tue, 29 Aug 2000 11:00:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from planar.cosmonet.org (kubo.j-phone.ne.jp [210.226.164.37]) by hub.freebsd.org (Postfix) with ESMTP id 0DC3B37B424 for ; Tue, 29 Aug 2000 10:51:55 -0700 (PDT) Received: from blanche.r-panda.private (dmax001-pool008.tokyo2.tnis.egg.or.jp [210.129.251.9]) by planar.cosmonet.org (8.8.8/3.7W) with ESMTP id CAA02429 for ; Wed, 30 Aug 2000 02:44:09 +0900 (JST) Received: (from cdr@localhost) by blanche.r-panda.private (8.9.3/3.7W) id CAA05675; Wed, 30 Aug 2000 02:48:07 +0900 (JST) Message-Id: <200008291744.CAA02429@planar.cosmonet.org> Date: Wed, 30 Aug 2000 02:48:07 +0900 (JST) From: Tatsuya Kudoh To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: i386/20925: doscmd(1) does not truncate a file Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >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