sbase

suckless unix tools
git clone git://git.suckless.org/sbase
Log | Files | Refs | README | LICENSE

commit 6bc2a3a18fda73247a254b30a1509a51fe0fc534
parent 7d1e7ae620f30e40f8863b6e653dbbf86eafb1f6
Author: Santtu Lakkala <inz@inz.fi>
Date:   Thu, 20 Nov 2025 15:27:52 +0200

ed: doread() minor refactoring

Swap n and len local variable names for clarity and matching getline()
documentation.

Diffstat:
Med.c | 16++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/ed.c b/ed.c @@ -799,10 +799,10 @@ static void doread(const char *fname) { size_t cnt; - ssize_t n; + ssize_t len; char *p; FILE *aux; - static size_t len; + static size_t n; static char *s; static FILE *fp; @@ -812,16 +812,16 @@ doread(const char *fname) error("cannot open input file"); curln = line2; - for (cnt = 0; (n = getline(&s, &len, fp)) > 0; cnt += (size_t)n) { + for (cnt = 0; (len = getline(&s, &n, fp)) > 0; cnt += (size_t)len) { chksignals(); - if (s[n-1] != '\n') { - if (n + 1 >= len) { - if (len == SIZE_MAX || !(p = realloc(s, ++len))) + if (s[len-1] != '\n') { + if (len+1 >= n) { + if (n == SIZE_MAX || !(p = realloc(s, ++n))) error("out of memory"); s = p; } - s[n] = '\n'; - s[n+1] = '\0'; + s[len] = '\n'; + s[len+1] = '\0'; } inject(s, AFTER); }