summaryrefslogtreecommitdiffstats
path: root/usr.bin/doscmd
diff options
context:
space:
mode:
authortg <tg@FreeBSD.org>2001-05-22 11:31:08 +0000
committertg <tg@FreeBSD.org>2001-05-22 11:31:08 +0000
commitd56823d7f2136e08fe33fd4a3cd2e173db2387bc (patch)
tree4e5292c107504a051db62dca623326a1c143d563 /usr.bin/doscmd
parent2486cc2c02b231ee090e81656a2e20d081c054e1 (diff)
downloadFreeBSD-src-d56823d7f2136e08fe33fd4a3cd2e173db2387bc.zip
FreeBSD-src-d56823d7f2136e08fe33fd4a3cd2e173db2387bc.tar.gz
Implement file truncation (DOS function 0x21, sub 0x40).
PR: 20925 Submitted by: Tatsuya Kudoh <cdr@cosmonet.org>
Diffstat (limited to 'usr.bin/doscmd')
-rw-r--r--usr.bin/doscmd/dos.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/usr.bin/doscmd/dos.c b/usr.bin/doscmd/dos.c
index d2d5f6d..43a290b 100644
--- a/usr.bin/doscmd/dos.c
+++ b/usr.bin/doscmd/dos.c
@@ -1309,6 +1309,22 @@ int21_3f(regcontext_t *REGS)
** 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;
@@ -1322,7 +1338,7 @@ int21_40(regcontext_t *REGS)
switch (R_BX) {
case 0:
if (redirect0) {
- n = write (R_BX, addr, nbytes);
+ n = write_or_truncate(R_BX, addr, nbytes);
break;
}
n = nbytes;
@@ -1331,7 +1347,7 @@ int21_40(regcontext_t *REGS)
break;
case 1:
if (redirect1) {
- n = write (R_BX, addr, nbytes);
+ n = write_or_truncate(R_BX, addr, nbytes);
break;
}
n = nbytes;
@@ -1340,7 +1356,7 @@ int21_40(regcontext_t *REGS)
break;
case 2:
if (redirect2) {
- n = write (R_BX, addr, nbytes);
+ n = write_or_truncate(R_BX, addr, nbytes);
break;
}
n = nbytes;
@@ -1348,7 +1364,7 @@ int21_40(regcontext_t *REGS)
tty_write(*addr++, -1);
break;
default:
- n = write (R_BX, addr, nbytes);
+ n = write_or_truncate(R_BX, addr, nbytes);
break;
}
if (n < 0)
OpenPOWER on IntegriCloud