Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F152637501
D25922.id75339.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D25922.id75339.diff
View Options
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,12 @@
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;
+ if (fwrite(argv[0], 1, len, stdout) != len)
+ err(1, "fwrite");
+ if (*++argv)
+ putchar(' ');
}
+ if (!nflag)
+ putchar('\n');
return 0;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 17, 4:39 AM (11 h, 44 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31639538
Default Alt Text
D25922.id75339.diff (2 KB)
Attached To
Mode
D25922: Revert echo(1) diet changes.
Attached
Detach File
Event Timeline
Log In to Comment