Page MenuHomeFreeBSD

D25922.id75341.diff
No OneTemporary

D25922.id75341.diff

Index: bin/echo/echo.c
===================================================================
--- bin/echo/echo.c
+++ bin/echo/echo.c
@@ -43,44 +43,16 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <sys/types.h>
-#include <sys/uio.h>
-
-#include <assert.h>
#include <capsicum_helpers.h>
#include <err.h>
-#include <errno.h>
-#include <limits.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-/*
- * Report an error and exit.
- * Use it instead of err(3) to avoid linking-in stdio.
- */
-static __dead2 void
-errexit(const char *prog, const char *reason)
-{
- char *errstr = strerror(errno);
- write(STDERR_FILENO, prog, strlen(prog));
- write(STDERR_FILENO, ": ", 2);
- write(STDERR_FILENO, reason, strlen(reason));
- write(STDERR_FILENO, ": ", 2);
- write(STDERR_FILENO, errstr, strlen(errstr));
- write(STDERR_FILENO, "\n", 1);
- exit(1);
-}
-
int
-main(int argc, char *argv[])
+main(int argc __unused, char *argv[])
{
int nflag; /* if not set, output a trailing newline. */
- int veclen; /* number of writev arguments. */
- struct iovec *iov, *vp; /* Elements to write, current element. */
- char space[] = " ";
- char newline[] = "\n";
- char *progname = argv[0];
if (caph_limit_stdio() < 0 || caph_enter() < 0)
err(1, "capsicum");
@@ -88,19 +60,13 @@
/* This utility may NOT do getopt(3) option parsing. */
if (*++argv && !strcmp(*argv, "-n")) {
++argv;
- --argc;
nflag = 1;
} else
nflag = 0;
- veclen = (argc >= 2) ? (argc - 2) * 2 + 1 : 0;
-
- if ((vp = iov = malloc((veclen + 1) * sizeof(struct iovec))) == NULL)
- errexit(progname, "malloc");
-
while (argv[0] != NULL) {
size_t len;
-
+
len = strlen(argv[0]);
/*
@@ -118,27 +84,14 @@
nflag = 1;
}
}
- vp->iov_base = *argv;
- vp++->iov_len = len;
- if (*++argv) {
- vp->iov_base = space;
- vp++->iov_len = 1;
- }
- }
- if (!nflag) {
- veclen++;
- vp->iov_base = newline;
- vp++->iov_len = 1;
- }
- /* assert(veclen == (vp - iov)); */
- while (veclen) {
- int nwrite;
-
- nwrite = (veclen > IOV_MAX) ? IOV_MAX : veclen;
- if (writev(STDOUT_FILENO, iov, nwrite) == -1)
- errexit(progname, "write");
- iov += nwrite;
- veclen -= nwrite;
+ (void)fwrite(argv[0], 1, len, stdout);
+ if (*++argv)
+ putchar(' ');
}
- return 0;
+ if (!nflag)
+ putchar('\n');
+ fflush(stdout);
+ if (ferror(stdout))
+ exit(1);
+ exit(0);
}

File Metadata

Mime Type
text/plain
Expires
Thu, Apr 16, 5:47 PM (52 m, 41 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31550701
Default Alt Text
D25922.id75341.diff (2 KB)

Event Timeline