aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Casino <mail@eduardocasino.es>2022-05-23 23:11:22 +0200
committerJavier <dev.git@javispedro.com>2022-06-12 17:13:03 +0200
commita56c45b42d5d1bf3b161d051fbe879454856b2ff (patch)
tree0c63217d473c09329d887d89d35fbd0dff42a539
parentb420e0ef35c368d648392ad675934af99d094ca6 (diff)
downloadvbados-a56c45b42d5d1bf3b161d051fbe879454856b2ff.tar.gz
vbados-a56c45b42d5d1bf3b161d051fbe879454856b2ff.zip
Truncate file to current position when writing 0 bytes
-rw-r--r--sftsr.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/sftsr.c b/sftsr.c
index 51388f1..b6d89c2 100644
--- a/sftsr.c
+++ b/sftsr.c
@@ -659,6 +659,27 @@ static void handle_write(union INTPACK __far *r)
return;
}
+ clear_dos_err(r);
+
+ // Mark the SFT as dirty and set date not valid any more
+ sft->dev_info &= ~(DOS_SFT_FLAG_CLEAN|DOS_SFT_FLAG_TIME_SET);
+
+ // Special case: If size is 0, truncate to current file position
+ if (!bytes) {
+
+ err = vbox_shfl_set_file_size(&data.vb, data.hgcm_client_id,
+ data.files[openfile].root, data.files[openfile].handle,
+ sft->f_pos);
+ if (err) {
+ set_vbox_err(r, err);
+ return;
+ }
+
+ sft->f_size = sft->f_pos;
+
+ return;
+ }
+
err = vbox_shfl_write(&data.vb, data.hgcm_client_id,
data.files[openfile].root, data.files[openfile].handle,
offset, &bytes, buffer);
@@ -675,11 +696,7 @@ static void handle_write(union INTPACK __far *r)
// Assume the file has grown if we've written past the end
if (sft->f_pos > sft->f_size) sft->f_size = sft->f_pos;
- // Mark the SFT as dirty
- sft->dev_info &= ~DOS_SFT_FLAG_CLEAN;
-
r->w.cx = bytes;
- clear_dos_err(r);
}
static void handle_commit(union INTPACK __far *r)