From b617b4cc5e45a82dcd6ae5211971ce9c4df3b627 Mon Sep 17 00:00:00 2001 From: 8nl <8nlight@disroot.org> Date: Mon, 8 Jan 2024 09:28:03 +0000 Subject: [PATCH] Upload files to "/" --- Makefile | 5 ++++ cutecat.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 Makefile create mode 100644 cutecat.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b139e77 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +CC?=cc +CFLAGS?=-Os -s + +all: + $(CC) $(CFLAGS) cutecat.c -o cutecat diff --git a/cutecat.c b/cutecat.c new file mode 100644 index 0000000..f01e922 --- /dev/null +++ b/cutecat.c @@ -0,0 +1,87 @@ +#include +#include +#include +#include +#include +#include +#include + +unsigned int d_flag; +char eyes[] = {'U', 'O'}; + +void OwO(char *buf, off_t len) { + if (d_flag) + return; + + for (int i = 0; i < len / 10; i++) { + size_t i = rand() % len; + + if (i + 3 < len && !isspace(buf[i]) && !isspace(buf[i + 2])) { + char eye = eyes[rand() % sizeof(eyes)]; + + buf[i] = eye; + buf[i + 1] = 'w'; + buf[i + 2] = eye; + } + } +} + +int cat(const char *path) { + int fd = STDIN_FILENO; + + if (strcmp(path, "-")) + fd = open(path, O_RDONLY); + + if (fd < 0) { + fprintf(stderr, "cat: %s: %s\n", path, strerror(errno)); + return 1; + } + + char buf[513]; + off_t len = 0; + while ((len = read(fd, buf, sizeof(buf))) > 0) { + OwO(buf, len); + if (write(STDOUT_FILENO, buf, len) != len) { + fprintf(stderr, "cat: %s\n", strerror(errno)); + return 1; + } + } + + if (strcmp(path, "-")) + close(fd); + + return 0; +} + +int main(int argc, char **argv) { + int opt; + while ((opt = getopt(argc, argv, "d")) != -1) { + switch (opt) { + case 'd': + d_flag = 1; + break; + + default: + printf("cutecat [file1 file2...]\n\t[-d Default mode]\n"); + return 0; + } + } + + argv += optind; + argc -= optind; + + if (!d_flag) + srand(getpid()); + + if (argc == 0) + return cat("-"); + + else { + int ret = 0; + for (int i = 0; i < argc; i++) + if (cat(argv[i])) + ret = 1; + + return ret; + } +}