X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=utils%2Fcat%2Fcat.c;fp=utils%2Fcat%2Fcat.c;h=0000000000000000000000000000000000000000;hb=4476699b7c7de3abf9f6da71ed409b2c032dc50f;hp=55b233bb412f69e01ce46080dd928759e660135f;hpb=2e838897cc574a9147bcf0b1681aeeaa44001fce;p=pdutils
diff --git a/utils/cat/cat.c b/utils/cat/cat.c
deleted file mode 100644
index 55b233b..0000000
--- a/utils/cat/cat.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * cat.c - concatenate file(s) to standard output
- *
- * Version: 2008-1.01
- * Build: c89 -o cat cat.c
- * Source:
- * Spec:
- *
- * This is free and unencumbered software released into the public domain,
- * provided "as is", without warranty of any kind, express or implied. See the
- * file UNLICENSE and the website for further details.
- */
-
-
-#define _POSIX_SOURCE
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#define USAGE "usage: cat [-u] [file ...]\n"
-#define BUFSIZE 4096
-
-static void catfile(int fd, char *fn);
-static void error(char *s);
-
-static int exitstatus;
-static int optu;
-
-
-int main(int argc, char **argv) {
- extern int opterr, optind;
- int c, fd;
- char *fn;
-
- setlocale(LC_ALL, "");
- opterr = 0;
-
- while ((c = getopt(argc, argv, "u")) != -1)
- switch (c) {
- case 'u':
- optu = 1;
- break;
- default:
- fprintf(stderr, USAGE);
- return(1);
- }
-
- if (optind >= argc)
- catfile(STDIN_FILENO, "stdin");
- else
- while (optind < argc)
- {
- fn = argv[optind++];
-
- if (strcmp(fn, "-") == 0)
- catfile(STDIN_FILENO, "stdin");
- else
- if ((fd = open(fn, O_RDONLY)) == -1)
- error(fn);
- else
- {
- catfile(fd, fn);
- if (close(fd) == -1)
- error(fn);
- }
- }
-
- return(exitstatus);
-}
-
-void catfile(int fd, char *fn) {
- unsigned char buf[BUFSIZE];
- ssize_t n;
-
- while ((n = read(fd, buf, (optu ? 1 : BUFSIZE))) > 0)
- if (write(STDOUT_FILENO, buf, (size_t)n) != n) {
- error("stdout");
- break;
- }
-
- if (n < 0) error(fn);
-}
-
-void error(char *s) {
- fprintf(stderr, "cat: %s: %s\n", s, strerror(errno));
- exitstatus = 1;
-}