URI: 
       ed: Implement non truncate writes - sbase - suckless unix tools
  HTML git clone git://git.suckless.org/sbase
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 5765a6e6b434ce692a15ed2e64bc2ea0d1c5a2e1
   DIR parent 08b8c73ddaf92727f8e9a93f2c0d60eb0183caa4
  HTML Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
       Date:   Sat, 13 Dec 2025 12:05:39 +0100
       
       ed: Implement non truncate writes
       
       The trunc parameter of dowrite() was ignored, making no difference
       between the w and W commands.
       
       Diffstat:
         M ed.c                                |       4 +++-
         A tests/0018-ed.sh                    |      20 ++++++++++++++++++++
       
       2 files changed, 23 insertions(+), 1 deletion(-)
       ---
   DIR diff --git a/ed.c b/ed.c
       @@ -761,6 +761,7 @@ dowrite(const char *fname, int trunc)
                FILE *aux;
                static int sh;
                static FILE *fp;
       +        char *mode;
        
                if (fp) {
                        sh ? pclose(fp) : fclose(fp);
       @@ -774,7 +775,8 @@ dowrite(const char *fname, int trunc)
                                error("bad exec");
                } else {
                        sh = 0;
       -                if ((fp = fopen(fname, "w")) == NULL)
       +                mode = (trunc) ? "w" : "a";
       +                if ((fp = fopen(fname, mode)) == NULL)
                                error("cannot open input file");
                }
        
   DIR diff --git a/tests/0018-ed.sh b/tests/0018-ed.sh
       @@ -0,0 +1,20 @@
       +#!/bin/sh
       +
       +tmp=tmp.$$
       +
       +trap 'rm -f $tmp' EXIT
       +trap 'rm -f $tmp; kill -KILL $$' HUP INT TERM
       +
       +touch $tmp
       +../ed -s $tmp <<EOF | (read a && test $a = 1)
       +a
       +1
       +.
       +w
       +,c
       +2
       +.
       +W
       +e
       +1p
       +EOF