ed: Don't clear modflag in shell escapes - sbase - suckless unix tools
HTML git clone git://git.suckless.org/sbase
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 08b8c73ddaf92727f8e9a93f2c0d60eb0183caa4
DIR parent 5364863516ace9b153ba5508c07baacef86127bc
HTML Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Sat, 13 Dec 2025 11:52:32 +0100
ed: Don't clear modflag in shell escapes
The function dowrite() is used for normal writes and for shell
escapes and in the second case we don't have the actual file
saved to disk.
Diffstat:
M ed.c | 3 ++-
A tests/0017-ed.sh | 11 +++++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
---
DIR diff --git a/ed.c b/ed.c
@@ -795,7 +795,8 @@ dowrite(const char *fname, int trunc)
if (r)
error("input/output error");
strcpy(savfname, fname);
- modflag = 0;
+ if (!sh)
+ modflag = 0;
curln = line;
if (optdiag)
printf("%zu\n", bytecount);
DIR diff --git a/tests/0017-ed.sh b/tests/0017-ed.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+../ed -s /dev/null <<EOF | grep 'file modified' > /dev/null
+a
+1
+2
+.
+w !echo
+q
+h
+EOF