Thanks, Laslo, and Micheal!
I decided to keep the fputs() for consistency's sake.

Here is the new patch:

>From a41d12fb9ef3fc36db34e7368b27d54413532165 Mon Sep 17 00:00:00 2001
From: Tait Hoyem <c...@tait.tech>
Date: Mon, 14 Sep 2020 22:18:57 +0000
Subject: [PATCH] Add bytecount print to 'w' command

---
 ed.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/ed.c b/ed.c
index cee9687..4fd7ccb 100644
--- a/ed.c
+++ b/ed.c
@@ -623,14 +623,18 @@ static void
 dowrite(const char *fname, int trunc)
 {
        FILE *fp;
+       size_t bytecount = 0;
        int i, line;

        if (!(fp = fopen(fname, (trunc) ? "w" : "a")))
                error("input/output error");

        line = curln;
-       for (i = line1; i <= line2; ++i)
-               fputs(gettxt(i), fp);
+       for (i = line1; i <= line2; ++i) {
+               gettxt(i);
+               bytecount += text.siz - 1;
+               fputs(text.str, fp);
+       }

        curln = line2;
        if (fclose(fp))
@@ -638,6 +642,7 @@ dowrite(const char *fname, int trunc)
        strcpy(savfname, fname);
        modflag = 0;
        curln = line;
+       printf("%zd\n", bytecount);
 }

 static void
--
2.28.0

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Monday, September 14, 2020 7:31 AM, Laslo Hunhold <d...@frign.de> wrote:

> On Sun, 13 Sep 2020 15:14:53 -0700
> Michael Forney mfor...@mforney.org wrote:
>
> Dear Michael,
>
> > I think we should use a different type than int here. I'm not sure if
> > size_t or off_t is more appropriate, but size_t is probably
> > reasonable.
>
> I think size_t is more reasonable here, because it's easier to work
> with (e.g. because it actually has POSIX-defined limits) and ed might
> work on pipe input that can exceed the file-size-limits, but probably
> not the memory-address-limits.
>
> With best regards
>
> Laslo



Reply via email to