--- bin/cat/cat.c.orig 2016-08-02 17:14:49.327387614 +0100 +++ bin/cat/cat.c 2016-08-04 12:57:06.657731370 +0100 @@ -48,18 +48,11 @@ #include #include -#ifndef NO_UDOM_SUPPORT -#include -#include -#include -#include -#endif #include #include #include #include -#include #include #include #include @@ -70,13 +63,10 @@ static const char *filename; static void usage(void) __dead2; -static void scanfiles(char *argv[], int cooked); -static void cook_cat(FILE *); -static void raw_cat(int); - -#ifndef NO_UDOM_SUPPORT -static int udom_open(const char *path, int flags); -#endif +void cook_args(char *argv[]); +void cook_buf(FILE *); +void raw_args(char *argv[]); +void raw_cat(int); /* * Memory strategy threshold, in pages: if physmem is larger than this, @@ -142,9 +132,9 @@ } if (bflag || eflag || nflag || sflag || tflag || vflag) - scanfiles(argv, 1); + cook_args(argv); else - scanfiles(argv, 0); + raw_args(argv); if (fclose(stdout)) err(1, "stdout"); exit(rval); @@ -160,51 +150,33 @@ /* NOTREACHED */ } -static void -scanfiles(char *argv[], int cooked) +void +cook_args(char *argv[]) { - int fd, i; - char *path; FILE *fp; - i = 0; - fd = -1; - while ((path = argv[i]) != NULL || i == 0) { - if (path == NULL || strcmp(path, "-") == 0) { - filename = "stdin"; - fd = STDIN_FILENO; - } else { - filename = path; - fd = open(path, O_RDONLY); -#ifndef NO_UDOM_SUPPORT - if (fd < 0 && errno == EOPNOTSUPP) - fd = udom_open(path, O_RDONLY); -#endif - } - if (fd < 0) { - warn("%s", path); - rval = 1; - } else if (cooked) { - if (fd == STDIN_FILENO) - cook_cat(stdin); - else { - fp = fdopen(fd, "r"); - cook_cat(fp); - fclose(fp); + fp = stdin; + filename = "stdin"; + do { + if (*argv) { + if (!strcmp(*argv, "-")) + fp = stdin; + else if ((fp = fopen(*argv, "r")) == NULL) { + warn("%s", *argv); + rval = 1; + ++argv; + continue; } - } else { - raw_cat(fd); - if (fd != STDIN_FILENO) - close(fd); + filename = *argv++; } - if (path == NULL) - break; - ++i; - } + cook_buf(fp); + if (fp != stdin) + (void)fclose(fp); + } while (*argv); } -static void -cook_cat(FILE *fp) +void +cook_buf(FILE *fp) { int ch, gobble, line, prev; @@ -264,7 +236,32 @@ err(1, "stdout"); } -static void +void +raw_args(char *argv[]) +{ + int fd; + + fd = fileno(stdin); + filename = "stdin"; + do { + if (*argv) { + if (!strcmp(*argv, "-")) + fd = fileno(stdin); + else if ((fd = open(*argv, O_RDONLY, 0)) < 0) { + warn("%s", *argv); + rval = 1; + ++argv; + continue; + } + filename = *argv++; + } + raw_cat(fd); + if (fd != fileno(stdin)) + (void)close(fd); + } while (*argv); +}; + +void raw_cat(int rfd) { int off, wfd; @@ -299,64 +296,3 @@ } } -#ifndef NO_UDOM_SUPPORT - -static int -udom_open(const char *path, int flags) -{ - struct addrinfo hints, *res, *res0; - char rpath[PATH_MAX]; - int fd = -1; - int error; - - /* - * Construct the unix domain socket address and attempt to connect. - */ - bzero(&hints, sizeof(hints)); - hints.ai_family = AF_LOCAL; - if (realpath(path, rpath) == NULL) - return (-1); - error = getaddrinfo(rpath, NULL, &hints, &res0); - if (error) { - warn("%s", gai_strerror(error)); - errno = EINVAL; - return (-1); - } - for (res = res0; res != NULL; res = res->ai_next) { - fd = socket(res->ai_family, res->ai_socktype, - res->ai_protocol); - if (fd < 0) { - freeaddrinfo(res0); - return (-1); - } - error = connect(fd, res->ai_addr, res->ai_addrlen); - if (error == 0) - break; - else { - close(fd); - fd = -1; - } - } - freeaddrinfo(res0); - - /* - * handle the open flags by shutting down appropriate directions - */ - if (fd >= 0) { - switch(flags & O_ACCMODE) { - case O_RDONLY: - if (shutdown(fd, SHUT_WR) == -1) - warn(NULL); - break; - case O_WRONLY: - if (shutdown(fd, SHUT_RD) == -1) - warn(NULL); - break; - default: - break; - } - } - return (fd); -} - -#endif --- bin/cat/cat.1.orig 2016-08-04 13:18:59.817392992 +0100 +++ bin/cat/cat.1 2016-08-04 13:21:26.308551048 +0100 @@ -32,7 +32,7 @@ .\" @(#)cat.1 8.3 (Berkeley) 5/2/95 .\" $FreeBSD: stable/11/bin/cat/cat.1 246090 2013-01-29 20:01:47Z joel $ .\" -.Dd January 29, 2013 +.Dd August 04, 2016 .Dt CAT 1 .Os .Sh NAME @@ -56,18 +56,6 @@ or absent, .Nm reads from the standard input. -If -.Ar file -is a -.Ux -domain socket, -.Nm -connects to it and then reads it until -.Dv EOF . -This complements the -.Ux -domain binding capability available in -.Xr inetd 8 . .Pp The options are as follows: .Bl -tag -width indent