Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F152695875
D25922.id75288.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.id75288.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,20 +60,11 @@
/* 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]);
/*
* If the next argument is NULL then this is this
@@ -109,36 +72,23 @@
* for a trailing \c.
*/
if (argv[1] == NULL) {
+ size_t len;
+
+ len = strlen(argv[0]);
/* is there room for a '\c' and is there one? */
if (len >= 2 &&
argv[0][len - 2] == '\\' &&
argv[0][len - 1] == 'c') {
/* chop it and set the no-newline flag. */
- len -= 2;
+ argv[0][len - 2] = '\0';
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)printf("%s", argv[0]);
+ if (*++argv)
+ putchar(' ');
}
+ if (!nflag)
+ putchar('\n');
return 0;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 17, 1:53 PM (20 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31637119
Default Alt Text
D25922.id75288.diff (2 KB)
Attached To
Mode
D25922: Revert echo(1) diet changes.
Attached
Detach File
Event Timeline
Log In to Comment