git: 7c0170ab9ff2 - stable/13 - echo(1): Replace errexit() with err(3)
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 07 Jan 2022 13:30:50 UTC
The branch stable/13 has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=7c0170ab9ff21d958654468f3bd95acee2896a98 commit 7c0170ab9ff21d958654468f3bd95acee2896a98 Author: Hans Petter Selasky <hselasky@FreeBSD.org> AuthorDate: 2021-11-09 21:09:46 +0000 Commit: Hans Petter Selasky <hselasky@FreeBSD.org> CommitDate: 2022-01-07 13:12:12 +0000 echo(1): Replace errexit() with err(3) Differential revision: https://reviews.freebsd.org/D32501 Submitted by: christos@ Sponsored by: NVIDIA Networking (cherry picked from commit 4c537df51a16ce004b184010d306e550716f49ea) --- bin/echo/echo.c | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/bin/echo/echo.c b/bin/echo/echo.c index f56bd5b976d8..46796ad1a27d 100644 --- a/bin/echo/echo.c +++ b/bin/echo/echo.c @@ -55,23 +55,6 @@ __FBSDID("$FreeBSD$"); #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[]) { @@ -80,7 +63,6 @@ main(int argc, char *argv[]) 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"); @@ -96,7 +78,7 @@ main(int argc, char *argv[]) veclen = (argc >= 2) ? (argc - 2) * 2 + 1 : 0; if ((vp = iov = malloc((veclen + 1) * sizeof(struct iovec))) == NULL) - errexit(progname, "malloc"); + err(1, "malloc"); while (argv[0] != NULL) { size_t len; @@ -135,7 +117,7 @@ main(int argc, char *argv[]) nwrite = (veclen > IOV_MAX) ? IOV_MAX : veclen; if (writev(STDOUT_FILENO, iov, nwrite) == -1) - errexit(progname, "write"); + err(1, "write"); iov += nwrite; veclen -= nwrite; }