Changeset View
Changeset View
Standalone View
Standalone View
bin/echo/echo.c
Context not available. | |||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.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 | int | ||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
Context not available. | |||||
veclen = (argc >= 2) ? (argc - 2) * 2 + 1 : 0; | veclen = (argc >= 2) ? (argc - 2) * 2 + 1 : 0; | ||||
if ((vp = iov = malloc((veclen + 1) * sizeof(struct iovec))) == NULL) | if ((vp = iov = malloc((veclen + 1) * sizeof(struct iovec))) == NULL) | ||||
errexit(progname, "malloc"); | err(1, "malloc"); | ||||
while (argv[0] != NULL) { | while (argv[0] != NULL) { | ||||
size_t len; | size_t len; | ||||
Context not available. | |||||
nwrite = (veclen > IOV_MAX) ? IOV_MAX : veclen; | nwrite = (veclen > IOV_MAX) ? IOV_MAX : veclen; | ||||
if (writev(STDOUT_FILENO, iov, nwrite) == -1) | if (writev(STDOUT_FILENO, iov, nwrite) == -1) | ||||
errexit(progname, "write"); | err(1, "write"); | ||||
iov += nwrite; | iov += nwrite; | ||||
veclen -= nwrite; | veclen -= nwrite; | ||||
} | } | ||||
Context not available. |