summaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
authorSören Tempel <soeren+git@soeren-tempel.net>2021-07-17 21:45:40 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-10-12 17:32:03 +0200
commitc33bbcb92fc255e4bb058e64874289cdeb0701f9 (patch)
tree29c40735df84c05f7a806d2fa1dd0d33768bde43 /editors
parent94c78aa0b91f2150bd038866addf3d0ee69474a8 (diff)
downloadbusybox-c33bbcb92fc255e4bb058e64874289cdeb0701f9.tar.gz
ed: align output of read/write commands with POSIX-1.2008
POSIX.1-2008 mandates the following regarding the write command: If the command is successful, the number of bytes written shall be written to standard output, unless the -s option was specified, in the following format: "%d\n", <number of bytes written> function old new delta readLines 447 409 -38 doCommands 1940 1889 -51 .rodata 104219 104163 -56 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/3 up/down: 0/-145) Total: -145 bytes Signed-off-by: Sören Tempel <soeren+git@soeren-tempel.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'editors')
-rw-r--r--editors/ed.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/editors/ed.c b/editors/ed.c
index c50faeefa..14540e566 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -380,7 +380,8 @@ static void addLines(int num)
static int readLines(const char *file, int num)
{
int fd, cc;
- int len, lineCount, charCount;
+ int len;
+ unsigned charCount;
char *cp;
if ((num < 1) || (num > lastNum + 1)) {
@@ -396,7 +397,6 @@ static int readLines(const char *file, int num)
bufPtr = bufBase;
bufUsed = 0;
- lineCount = 0;
charCount = 0;
cc = 0;
@@ -415,7 +415,6 @@ static int readLines(const char *file, int num)
bufPtr += len;
bufUsed -= len;
charCount += len;
- lineCount++;
num++;
continue;
}
@@ -449,15 +448,18 @@ static int readLines(const char *file, int num)
close(fd);
return -1;
}
- lineCount++;
charCount += bufUsed;
}
close(fd);
- printf("%d lines%s, %d chars\n", lineCount,
- (bufUsed ? " (incomplete)" : ""), charCount);
-
+ /* https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html
+ * "Read Command"
+ * "...the number of bytes read shall be written to standard output
+ * in the following format:
+ * "%d\n", <number of bytes read>
+ */
+ printf("%u\n", charCount);
return TRUE;
}
@@ -468,12 +470,12 @@ static int readLines(const char *file, int num)
static int writeLines(const char *file, int num1, int num2)
{
LINE *lp;
- int fd, lineCount, charCount;
+ int fd;
+ unsigned charCount;
if (bad_nums(num1, num2, "write"))
return FALSE;
- lineCount = 0;
charCount = 0;
fd = creat(file, 0666);
@@ -482,9 +484,6 @@ static int writeLines(const char *file, int num1, int num2)
return FALSE;
}
- printf("\"%s\", ", file);
- fflush_all();
-
lp = findLine(num1);
if (lp == NULL) {
close(fd);
@@ -498,7 +497,6 @@ static int writeLines(const char *file, int num1, int num2)
return FALSE;
}
charCount += lp->len;
- lineCount++;
lp = lp->next;
}
@@ -507,7 +505,13 @@ static int writeLines(const char *file, int num1, int num2)
return FALSE;
}
- printf("%d lines, %d chars\n", lineCount, charCount);
+ /* https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html
+ * "Write Command"
+ * "...the number of bytes written shall be written to standard output,
+ * unless the -s option was specified, in the following format:
+ * "%d\n", <number of bytes written>
+ */
+ printf("%u\n", charCount);
return TRUE;
}