From cdr@cosmonet.org  Tue Aug 29 10:51:57 2000
Return-Path: <cdr@cosmonet.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 <FreeBSD-gnats-submit@freebsd.org>; 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 <FreeBSD-gnats-submit@freebsd.org>; 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 <cdr@cosmonet.org>
To: FreeBSD-gnats-submit@freebsd.org
Subject: doscmd(1) does not truncate a file
X-Send-Pr-Version: 3.2

>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:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Aug 29 11:00:01 PDT 2000
>Closed-Date:    Fri May 25 05:31:11 PDT 2001
>Last-Modified:  Fri May 25 05:31:37 PDT 2001
>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:
State-Changed-From-To: open->closed 
State-Changed-By: tg 
State-Changed-When: Fri May 25 05:31:11 PDT 2001 
State-Changed-Why:  
Committed, thanks. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=20925 
>Unformatted:
